Scenario: the content of a character string is matched, and the character string is changed to another one. However, the client of the released version must support string matching of the old version. Example: Old string: android3601.0 New String: androidaaa3601.0 now want to write a regular table... scenario:
The content of a character string is matched, and the character string is changed to another one. However, the client of the released version must support string matching of the old version.
Example:
Old string: android/360 1.0
New String: android/aaa/360/1 .0
Now I want to write a regular expression that matches both the old string and the new string.
Is there a way to select an expression based on a condition?
Old expressions match Regular Expressions:
([IOS | android]) \ Scoco/([\ S \ s]) \ S ([\ S] *)
Old regular expression test string
Android coco/360 1.0
The new expression matches the regular expression:
"([IOS | android]) [\ S | \ S] coco/([\ S])/([\ S])/([\ S])/([0-9]) ";
New Regular Expression test string:
Android coco/android_deviceId/360/1 .0/123456
How can we make a regular expression support both new and old expressions?
([iOS|android]*)[\\s|\\S]coco/[([\\S\\s]*)\\s([\\S]*)] `**|**` [([\\S]*)/([\\S]*)/([\\S]*)/([0-9])]
Similar to the above error regular expression. How to write?
Reply content:
Scenario:
The content of a character string is matched, and the character string is changed to another one. However, the client of the released version must support string matching of the old version.
Example:
Old string: android/360 1.0
New String: android/aaa/360/1 .0
Now I want to write a regular expression that matches both the old string and the new string.
Is there a way to select an expression based on a condition?
Old expressions match Regular Expressions:
([IOS | android]) \ Scoco/([\ S \ s]) \ S ([\ S] *)
Old regular expression test string
Android coco/360 1.0
The new expression matches the regular expression:
"([IOS | android]) [\ S | \ S] coco/([\ S])/([\ S])/([\ S])/([0-9]) ";
New Regular Expression test string:
Android coco/android_deviceId/360/1 .0/123456
How can we make a regular expression support both new and old expressions?
([iOS|android]*)[\\s|\\S]coco/[([\\S\\s]*)\\s([\\S]*)] `**|**` [([\\S]*)/([\\S]*)/([\\S]*)/([0-9])]
Similar to the above error regular expression. How to write?
There is a big difference between the two strings, so there is no need to compress them into a regular expression. It is more appropriate to divide them into two regular expressions.
There is no matching rule definition in the regular expression based on the condition.|
. The effect is no different from the two regular expressions.
The most violent solution: Use "or "(|
)
Elegant solution: extract two public features that match strings and write new regular expressions for compatibility