user3684829
user3684829

Reputation: 15

Regex to match the dollar in a string

I'd like to match everything behind value:, including words, hypen, underscore and dollar sign.

Like:

Value:      -A--C_Df-$    

Or

Value:      -A--C_Df

Or the easy one:

Value:      ACDF

How do i cover the dollar sign? My Regex works except the dollar sign:

m/Value:(\s+|\t+)([a-zA-z_-]*)/

Upvotes: 0

Views: 866

Answers (4)

Miller
Miller

Reputation: 35208

Just use the any character .:

m/Value:\s*(.*)/

If you want to use a character class, you just need to escape the dollar sign and the dash that's a literal:

m/Value:\s*([a-zA-Z_\-\$]*)/

Upvotes: 1

Eric Seifert
Eric Seifert

Reputation: 2032

Why not just:

m/Value:\s*(\S+)/

That will match zero or more white space chars (no need for \t, \s includes tabs), followed by one or more non whitespace chars that you can extract.

Upvotes: 0

tenub
tenub

Reputation: 3446

You didn't specify the dorrar sign?

m/Value:(\s+)([\w$-]*)/

Upvotes: 0

Explosion Pills
Explosion Pills

Reputation: 191789

You say you want to match everything, so why not just .*? Otherwise you can just include the $ in your character class:

m/Value:(\s+)([a-zA-Z_$-]*)/

Note that \t is covered by \s.

Upvotes: 1

Related Questions