写一个正则表达式来提取'/'之前的数字 [英] Write a Regex to extract number before '/'
本文介绍了写一个正则表达式来提取'/'之前的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不想使用字符串拆分,因为我有数字 1-99,以及文本中某处包含#/#"的字符串列.
I don't want to use string split because I have numbers 1-99, and a column of string that contain '#/#' somewhere in the text.
如何编写正则表达式来提取以下示例中的数字 10:
How can I write a regex to extract the number 10 in the following example:
He got 10/19 questions right.
推荐答案
使用前瞻来匹配/
,像这样:
Use a lookahead to match on the /
, like this:
\d+(?=/)
如果您的实现使用它作为分隔符,您可能需要转义/.
You may need to escape the / if your implementation uses it as its delimiter.
实例:https://regex101.com/r/xdT4vq/1
这篇关于写一个正则表达式来提取'/'之前的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文