Regex matches all but not empty

The string must be validated with a regular expression,

  • a string can contain any characters, spaces, numbers, floats.

  • the line should not be empty

I tried this:

[A-Za-z0-9~`!#$%^&*()_+-]+ //thinking of all the characters

Any alternative solution would be helpful

+5
source share
7 answers

Try this to match a string containing more than just spaces

/.*\S.*/

It means

/= delimiter
.*= zero or nothing more than a new line
\S= everything except spaces (new line, tab, space)

so that you get a match nothing but a new line + something not whitespace + nothing but a new line

, /.+/, 1 .

+11

: [^()]

python re.match():

  >>> re.match( r"[^()]", '' )
  >>> re.match( r"[^()]", ' ' )
  <_sre.SRE_Match object at 0x100486168>
+6

, ^$, , , , .

+2

:

[.]+

, .

0

:

^.+$

python BeautifulSoup , , . . :

# get first 'a' tag in the html content where 'href' attribute is not empty
parsed_content.find("a", {"href":re.compile("^.+$")})
0

1 :

(.*?(\n))
0

, NOT BLANK:

^(\s|\S)*(\S)+(\s|\S)*$

Empty lines are those that contain only empty characters (tabs, spaces, etc.).

-1
source

All Articles