Regex to match dollar sign and following spaces

As the title says, I need to create a regex that matches $ and any following space after it. Example:

"asd $   5" should match "$   ".

Is is possible? I could find anything like that.

Upvotes: 5

Views: 10359

Answers (3)

moham_arshed
moham_arshed

Reputation: 11

You can also get with \$\s+

Make sure to put escape character before $ since $ also indicates end of string in regex

Upvotes: 1

kiner_shah
kiner_shah

Reputation: 4641

You may use the following regex:

[$]\s+

[$] will match the dollar sign, and \s+ will match one or more spaces after the dollar sign.

See test example here: https://regex101.com/r/Y4j98L/1

Upvotes: 10

mahesh
mahesh

Reputation: 1098

For the dollar sign, you need to escape the sign. So \$\s* would match what you want. I interpret "any matching spaces" as there being a possibility of there being no spaces as well.

Upvotes: 3

Related Questions