Reputation: 331
hi i want to use regular expression with this kind of string, but i can't figure out how to do this. i try to use
\s\s5 to find this string. but i also find some string like \s\s\s\s5
123
4567
5
5
5
5
you can see that there are some structure that we i need to deal with. is there anyway that i can match the
<whitespace><whitespace>5
but not to match the string with more than two whitespace?
<whitespace><whitespace><whitespace><whitespace>5
Upvotes: 0
Views: 86
Reputation: 34587
In a regular expression language where \s is a whitespace:
[^\s]\s\s5
(this will find any instance of 5 which follows 2 whitespaces, i.e. "abc 5" would match; not sure if this is your question or you are asking about beginning of the string, others have responded to that)
Upvotes: 0
Reputation: 5077
You need to indicate that you're looking for a full line:
^\s\s(\d+)$
where the ^
marks the start of the line and the $
the end of the line.
It also depends which language you're working in, because Java's java.util.regex.Matches
has a find()
method that will match inside a String, and a matches()
method that will match an entire string.
Upvotes: 0
Reputation: 141868
Anchor your regular expression to the start of the line (^
):
^\s\s5
Upvotes: 4