ruby - a regex for numbers, letters, and -_. but the -_. can't be last characters of the captured fragment -
How do I create a regex that captures this form as:
"BS BN12 .3 .- "Scan (Reggae) # = & gt; [["12.3"]]
Where are the last time, underscore, and hyphen are not included in the capture, but are the internal ones? I tried the following:
"BS BN12.3." Scan (/ BN ([a-zA-Z0-9 \ -_.] +) /) #) = & Gt; If you create your existing group as a non-governmental organization, do it ? By terminating as ([a-zA-Z0- 9 \ -_. >> +?)
as
and follow it with an expression that is different from the other The letter [-._] *
before ending with $
, you should do what you need: "bs BN12.3.-" .scan (/ bn ([a-zA-Z0-9 \ -_.] +?) [-__ * * $ /) = & gt; [["12.3"]] # Various input string ... "BS BN12.3" .scan (/ BN ([a-zA-Z0-9 \ -_.] +?) [-._] * $ / ) = & Gt; [["12.3"]] 2.1.0: 012 & gt; "BS BN 12." Scan (/ BN ([A-GAA-Z-9-9. -_.] +?) [-__ * * $ /) => [["12"]] "BS BN 12.3-4.5 ______". Scan (/ BN ([A-GAA-Z. 0-9. -Y] +?) [-._] * $ /) = & gt; [["12.3-4.5"]
(Note: Most punctuation is not required to escape inside the []
character class. Its current status
Appendix: Any non-alphabet, in order to prevent non-end characters To define, the last character class can be [^ A-Za-z0- 9] *
"BS BN12.3-4.5 ______" .scan ( / BN ([a-zA-Z0-9 \ -_.] +?) [^ Azza-j 0-9] * $ /) = & gt; [["12.3-4.5"]
Comments
Post a Comment