简体   繁体   中英

Microsoft regular expression pattern failed to match

I was trying to use my regex with the options: ignore case, multiline, and ignore white space. But it fails to match. Here's the regex:

"  
\s+(?(U|US|USD)\s*\$\s([a-z0-9$,.'_-]+)(\s[a-z0-9$,.'_-]+)+)\s+(\-\s(Savings|Chequing|\w+)\s(\d{5})\-(\d{7})\s*){0,1}
(Savings|Chequing|\w+)\s(?\d{5}\-(\d{7}))\s+(Available Balance[:]\s[$](?[0-9.,]{3,20})\sUSD\s
[$](?[0-9,.]{3,20}))
"

Here's an example of a string I want to match:

"Close Quick Menu Button
                 U$ smith Hi interest2 
Savings 04237-4500385 Available Balance: $0.00 USD 
$0.00 USD 
Open r"

I think I made mistake is (?<availBal>[0-9.,]{3,20})\\s because the expression matches using the preceding part of the expression

I have been trying with different patterns with no avail.

Your help is much appreciated.

The thing I'm noticing is you have Available Balance right in the middle of your regex.

You need to change that to Available\\sBalance . When it says it ignores whitespace, that means whitespace in the regex not the string you match against.


This regex works. I changed the (? to (?: and I added a + .

\s+(?:(U|US|USD)\s*\$\s([a-z0-9$,.'_-]+)(\s[a-z0-9$,.'_-]+)+)\s+(\-\s(Savings|Chequing|\w+)\s(\d{5})\-(\d{7})\s*){0,1}(Savings|Chequing|\w+)\s(?:\d{5}\-(\d{7}))\s+(Available\sBalance[:]\s[$](?:[0-9.,]{3,20})\sUSD\s+[$](?:[0-9,.]{3,20}))

But you're ignoring whitespace, so why not write this legibly? I also changed some unnecessary things you had:

\s+(?:(U|US|USD) \s* \$ \s ([a-z0-9$,.'_-]+)
   (\s[a-z0-9$,.'_-]+)+)
\s+(-\s(Savings|Chequing|\w+)
\s (\d{5})-(\d{7})\s*)?
   (Savings|Chequing|\w+)
\s (?:\d{5}-(\d{7}))
\s+(Available \s Balance: \s \$ (?:[0-9.,]{3,20}) \s USD
\s+\$(?:[0-9,.]{3,20}))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM