Tag: regex lookarounds

正则表达式,在Ruby中具有前瞻性

我当前的正则表达式之争是在字符串中的数字前替换所有逗号。 然后正则表达式必须忽略所有后续逗号。 我已经在rubular上拧了大约一个小时,看起来似乎无法正常工作。 测试字符串…… ‘this is, a , sentence33 Here, is another.’ 期望的输出…… ‘this is comma a comma sentence33 Here, is another.’ 所以有些东西…… testString.gsub(/\,*\d\d/,”comma”) 为了给你一些背景知识,我正在做一些有趣的侧面项目。 我收集的元素主要以逗号分隔,从两位数年龄开始。 然而,有时候可能包含逗号的年龄前的标题。 为了保留我稍后设置的结构,我需要替换标题中的逗号。 在尝试叠加溢出之后的答案…… 我还有一些问题。 不要笑,但这里是从屏幕抓取导致问题的实际线… statsString = ” 23, 5’9\”, 140lb, 29w, Slim, Brown Hair, Shaved Body, White, Looking for Friendship, 1-on-1 Sex, Relationship. Out Yes,SmokeNo,DrinkNo,DrugsNo,ZodiacCancer. Versatile, 7.5\” Cut, […]