Scala Anchored Regex acts as unachored -


so reason in scala 2.11, anchored regex patterns act unanchored regex patterns.

scala> """something\.com""".r.anchored findfirstin "app.something.com" res66: option[string] = some(something.com) scala> """^.something\.com$""".r.anchored findfirstin "app.something.com" res65: option[string] = none 

i thought first expression evaluate none second (manually entered anchors) not.

any appreciated.

the findfirstin method un-anchors regex automatically.

you can see example code matches a only:

example:
"""\w+""".r findfirstin "a simple example." foreach println // prints "a"

btw, once create regex "pattern".r, anchored default, matters when use regex in match block. inside findallin or findfirstin, type of anchoring ignored.

so, make sure regex matches whole string, add ^ , $ (or \a , \z) anchors if not sure going use regexes.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

Ansible warning on jinja2 braces on when -