A line has to be validated through regex,
line can contain any characters, spaces, digits, floats.
line should not be blank
I tried this:
[A-Za-z0-9~`!#$%^&*()_+-]+ //thinking of all the characters
Any alternative solution will be helpful
A line has to be validated through regex,
line can contain any characters, spaces, digits, floats.
line should not be blank
I tried this:
[A-Za-z0-9~`!#$%^&*()_+-]+ //thinking of all the characters
Any alternative solution will be helpful
Try this to match a line that contains more than just whitespace
/.*\S.*/
This means
/ = delimiter
.* = zero or more of anything but newline
\S = anything except a whitespace (newline, tab, space)
so you get
match anything but newline + something not whitespace + anything but newline
if whitespace only line counts as not whitespace, then replace the rule with /.+/, which will match 1 or more of anything.
try:
.+
The . matches any character, and the plus requires least one.
Try : [^()]
In python with re.match() :
>>> re.match( r"[^()]", '' )
>>> re.match( r"[^()]", ' ' )
<_sre.SRE_Match object at 0x100486168>
You could just check if the line matches ^$ if it does then it's blank and you can use that as a failure, otherwise it will pass.
Try this:
^.+$
I used this in python BeautifulSoup when trying to find tags which do not have an attribute that is empty. It worked well. Example is below:
# get first 'a' tag in the html content where 'href' attribute is not empty
parsed_content.find("a", {"href":re.compile("^.+$")})
try
^[A-Za-z0-9,-_.\s]+$
this string will return true for alphabets, numbers and ,-_. but will not accept an empty string.
+ -> Quantifier, Matches between 1 and unlimited.
* -> Quantifier, Matches between 0 and unlimited.
This one will match everything but NOT BLANK string:
^(\s|\S)*(\S)+(\s|\S)*$
Blank string is those containing empty characters only (tabs, spaces etc.).
^\S+[^ ]$
^ - beginning of line
\S - any non-whitespace character
+ - one or more occurence
[^ ] - character not in the set (in this case only space), there is a space between ^ and ] this will match dsadasd^adsadas
$ - end of line
.* - matches between zero and unlimited times any character (except for line terminators)
\S - matches any non-whitespace character
Answer: .*[\S].*
'aaaaa' match
'aaaaa ' match
' aaaaa' match
' aaaaa ' match
'aaaaa aaaaa aaaaa' match
' aaaaa aaaaa aaaaa' match
'aaaaa aaaaa aaaaa ' match
' aaaaa aaaaa aaaaa ' match
' ' does not match
You can test this regular expression at: https://regex101.com