简体   繁体   中英

Trouble determining the pattern for NSRegularExpression…?

i am relatively new to NSRegularExpression and just can't come up with a pattern to find a string within a string.... here is the string...

#@$294@001@[12345-678[123-456-7@15665@2

I want to extract the string..

@001@[12345-678[123-456-7@

for more info I know that there will be 3 digits(like 001 ) between two @ 's and 20 characters between the last two @ 's..

I have tried n number of combinations but nothing seem to work. any help is appreciated.

How about something like this:

@[0-9]{3}@.{20}@

If you know that the 20 characters will always consist of digits, [ and - , your pattern would become:

@[0-9]{3}@[0-9\[\-]{20}@

Be careful with the backslashes: When you use create the pattern with a string literal ( @"..." ), you need to add an extra backslash before each backslash.

您可以使用RegexTester测试NSRegularExpression模式而无需每次重新编译https://github.com/liyanage/regextester

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