Why doesn't this regex work as expected in Java? -


trivial regex question (the answer java-specific):

"#this comment in file".matches("^#") 

this returns false. far can see, ^ means means , # has no special meaning, i'd translate ^# "a '#' @ beginning of string". should match. , does, in perl:

perl -e "print '#this comment'=~/^#/;" 

prints "1". i'm pretty sure answer java specific. please enlighten me?

thank you.

matcher.matches() checks see if entire input string matched regex.

since regex matches first character, returns false.

you'll want use matcher.find() instead.

granted, can bit tricky find concrete specification, it's there:


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -