tags:

views:

36

answers:

2

Hi,

I would like to check whether a given text begins with some currency symbols, like $€£¥. how to achieve that using regex

+3  A: 

Depending on your language, but something like ^[\$€£¥].*

[] is a character group matching one of the characters inside.

You might have to write \$ because the $-sign has sometimes special meaning in regexps.

.* matches "everything else" (except a newline).

Edit: After re-reading your question: If you really want to match some currency symbols (maybe more than one), try ^[\$€£¥]+.*

phimuemue
Don't forget the ^ to indicate start of text, and a currency value will typically only have one currency symbol
Mark Baker
You missed "^" at the beggining because @Sri wants to know if that chars in begining of the text
antyrat
Thank you, I added `^`, and yep, you're correct, that a currency value usually has just one currency symbol, but Sri just wanted to check whether a string begins with a currency symbol.
phimuemue
@phim: inside character classes `$` doesn't require escaping.
SilentGhost
+1  A: 

Which regex flavor? If it's one that supports Unicode properties, you can use this:

^\p{Sc}

(I didn't add quotes or regex delimiters because I don't know which flavor you're using.)

Alan Moore