Reputation: 1
I would like some help in getting this regex to accept the space character.
The following regex works ^a|a$|a
but this one doesn't ^tips to|tips to$|tips to
.
Upvotes: 0
Views: 152
Reputation: 675
try escaping just the last space (the regex engine will then "see" that "tips to" is one block - at least for the last OR)
^tips to|tips to$|tips\ to
or to be on the safe side group what your searching for
^(tips to)|(tips to)$|(tips to)
[EDIT 1]
so here's the solution the OP is using:
^"tips to"|"tips to"$|"tips to"
Upvotes: 0
Reputation: 36339
The regular expression that matches 1 space character is 1 space character.
Upvotes: 0
Reputation: 25873
Space is just as-is in a regex (you just put the space character, that should work). Alternatively you can use \s special character. For example, in Perl:
my $test = "Helloworld";
if ($test =~ m/ /)
{
print("Has space\n");
}
Also if you can specify more what you want to use the regex for, we might be able to help better.
Upvotes: 1