Reputation: 13025
I want to find the strings that share the following pattern:
The first character is + and the last character is a space. There can have more than one characters between these two characters. They can be a digit or a digit or a letter, or any other character, such as *, &, etc. But they can not be space. In other words, there only has one space for this string and is at the end position.
How to represent this pattern using regular expression?
Upvotes: 1
Views: 65
Reputation: 455020
You can try the regex
\+[^ ]+
There is a space at the end of the above regex.
Upvotes: 0
Reputation: 175375
^
matches the beginning of a string, and $
the end. You can make a character class with []
that matches only the things in the class, and ^
at the beginning makes it match anything not in the class, so [^ ]
means "anything except a space". So the complete match is:
^\+[^ ]* $
Upvotes: 5