ruby - Regular expressions - Unable to match this string -


i writing ruby script requiring pattern matching. got unable match long string of 01122223_200000_1717181 on using / (\d+\_+\d+)*/.

it's matching following pattern though / \**|type:|\=*/. can't figure out why. have checked ordering of pattern matching too.

does have suggestion?

you have more 1 thing going on pattern, think 1 causing matching fail:

  • your parentheses off.
  • you have + after underscore, don't think want/need one.
  • you have whitespace @ beginning of pattern.

of these, issue preventing getting match last one. rest of pattern should still match, though not quite way want (meaning it'll match things wouldn't want match). i'd go this:

/\d+(_\d+)+/ 

if want accept pattern no underscores (e.g. 999999), use this:

/\d+(_\d+)*/ 

about second question: reason it's matching / \**|type:|\=*/ \** , \=* use * quantifier, rather +. means they'll match if input contains no * or = characters @ all. \=* matches empty string, that expression match input. change / \*+|type:|\=+/ , shouldn't match anymore.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -