Regex not matching
NickName:blue-sky Ask DateTime:2015-01-19T20:14:08

Regex not matching

I expect regex "[a-zA-Z]\\d{6}" to match "z999999" but it is not matching as an empty List is mapped :

val lines = List("z999999");                      //> lines  : List[String] = List(z999999)

val regex = """[a-zA-Z]\d{6}""".r                 //> regex  : scala.util.matching.Regex = [a-zA-Z]\d{6}

val fi = lines.map(line => line match { case regex(group) => group case _ => "" })
                                                  //> fi  : List[String] = List("")

Is there a problem with my regex or how I'm using it with Scala ?

Copyright Notice:Content Author:「blue-sky」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28024438/regex-not-matching

More about “Regex not matching” related questions

Regex not matching

I expect regex "[a-zA-Z]\\d{6}" to match "z999999" but it is not matching as an empty List is mapped : val lines = List("z999999"); //> lines : List[String] = List(z99999...

Show Detail

Incremental regex matching

Problem: The program needs to read from an input stream of characters, and match the input against a predefined list of regex patterns. The program should report a match as soon as it is found (rep...

Show Detail

Regex not matching in Go

I have a regex that is not matching in Go. However in a regex playground it's matching fine: https://regex101.com/r/VNDXcQ/2. It's matching JS comments. Here is the code: comment := "// fallback

Show Detail

regex matching tutorial

I've been using regex for years, I've read several tutorials and references (emacs regex reference is my bible), but I still have problems understanding matching. Is there a good comprehensive tuto...

Show Detail

Trouble with Regex matching in Perl

I'm having trouble matching a regex in Perl and was wondering if anyone had any insight: Here is my regex: /^-MEMBER:\s+(\b[^,]+)(?:,\s(\b.{1,50}\b)\.?)?\s+ID#:\s+(\d+)$/ Here is what I'm matchin...

Show Detail

Wrong matching regex

So I'm using re module to compile my regex, and my regex looks like this: "(^~\w+?[ & ~\w+?]*?$)" So I compile it using pattern = re.compile(regex) and then I use re.findall(pattern, string...

Show Detail

Regex not matching URL

I have regex expression (1) which matches the URL specified below. However I have problem creating a regex for input URL (see not matching). Any ideas how to do this on regex where user can input a...

Show Detail

regex not matching in findText()

I was trying to change color to some text in a document, and I required regexp. So, I tried the function findText to search where my text is in the selected text, but I am having some troubles matc...

Show Detail

Matching multiple terms with regex

This is response to my previous thread (Matching data from file with regex) However it was matching only one keyword "DATA", but the file contains 20 others in the same format, but I only want to ...

Show Detail

Regex Matching bigger String first

I am trying to match this string: www.abcdgbs.com/p/Flights/abcd with regex regex = ".*(/Hotels|(/p)?/Flights).*"; pipe separated for matching from multiple regex I want to get the index where...

Show Detail