My text can contain values like these:-
[Other]
A,B,[Other]
[Other][N/A]
[Other]Hello
[Other]Hello,baby
I want a regex expression which can satisfy only case 4 and 5. For the first three cases, it should fail. In my case, [Other] is fixed in the string value. We can simplify the regex with hardcode of [Other]. For case, event text [N/A] is fixed, so that makes it different from case 4 and 5.
Pls help and suggest the regex expression.
For testing, pls use http://www.gskinner.com/RegExr/
试试这个regex
:
^\[[^\]]+\][a-zA-Z,]+$
Depends what exactly you want to match, but this works for your case
^\[Other\][^\[]+$
Which breaks down like... start ( ^
) followed by the string [Other]
(escaped) followed by not [
( [^\\[]
) one or more times ( +
) followed by end ( $
)
EDIT Or a more specific version (as per comment) is as above, but second half has not [
followed by not N
followed by not \\
optionally, followed by not A
optionally, followed by not ]
followed by zero or more of any character ( .*
) end ( $
)
^\[Other\][^\[][^\N]?[^\\]?[^A]?[^\]]?.*$
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.