英文:
Regex to match multiple string conditions
问题
以下是代码部分,不做翻译:
(?\<Group1\>(?:(.) ())|.*
(?\<Group1\>*.[a-zA-Z] )|(.*)
以下是翻译好的部分:
I have a need to capture two different string types returned by a query. The first string has data that needs to be trimmed off while the second string is just text.
Review / Sign Changes
City & State for Current Visit
I tried
(?\<Group1\>(?:(.) ())|.*
(?\<Group1\>*.[a-zA-Z] )|(.*)
I expected:
Review / Sign Changes
City & State for Current Visit
I'm not strong in Regex but I try :) Any help would be appreciated.
英文:
I have a need to capture two different string types returned by a query. The first string has data that needs to be trimmed off while the second string is just text.
Review / Sign Changes (Doe,John Howard - 555-00-5555)
City & State for Current Visit
I tried
(?\<Group1\>(?:(.) ())|.\*
(?\<Group1\>\*.\[a-zA-Z\] )|(.\*)
I expected:
Review / Sign Changes
City & State for Current Visit
I'm not strong in Regex but I try Any help would be appreciated.
答案1
得分: 2
这个正则表达式:
^[^(]+
正则表达式的匹配如下:
节点 | 解释 |
---|---|
^ |
字符串的开头 |
[^(]+ |
除了 ( 之外的任何字符(1次或多次(尽可能匹配最多的字符)) |
英文:
This regex:
^[^(]+
The regular expression matches as follows:
Node | Explanation |
---|---|
^ |
the beginning of the string |
[^(]+ |
any character except: ( (1 or more times (matching the most amount possible)) |
答案2
得分: 1
如果第一个字符串的格式保持一致,您可以跳过正则表达式,只需按两个空格拆分字符串并取第一部分。对于第二个字符串,我看不到任何更改,所以您不需要使用正则表达式。
英文:
If the formatting of the first string is consistent, you can skip regex and just split the string by two spaces and take the first part. For the second string, I see no changes at all so you shouldn't need a regex there.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论