目前我的正则表达式是你好 我怎么能允许你好或你好,即。在单词之后或者字符之后必须有任何内容,它可能只是一个空格。 谢谢, Rix 编辑: 我现在有
(([。])|([]))hello \\\ | \(hello \)匹配: .hello。 你好 (你好) 但不是x你好 我以前怎样才能允许任何事情? 我尝试了什么: 查找正则表达式而不理解模式
解决方案试试这个: hello \s?
\s一个空格 ?重复零或一次
转到RegExr:学习,构建和测试RegEx [ ^ ]。
TRo加入Pete Leow的建议:你好不符合只是你好,而hello \s?不仅仅是将hello与后面的空格匹配。它也匹配 你好那里你好 - 那里why-hello!
和在该序列中连续包含字母hello的任何其他内容。 如果您想完全匹配hello或hello,那么您需要:
^ hello\s?Hi, Currently my regex pattern is "hello" How can I allow either "hello" or "hello ", ie. there must be either nothing after the word or the character directly after it may only be a space. Thanks, Rix EDIT: I now have
(([."])|([ ]))hello\2|\(hello\)which matches: .hello. "hello" (hello) but not x hello How can I allow anything before? What I have tried: Looking up regex and not understanding the patterns
解决方案 Try this:hello\s?\s for one space ? repeat zero or once
Go to RegExr: Learn, Build, & Test RegEx[^].TRo add to Pete Leow's suggestion: "hello" doesn't match just "hello", and "hello\s?" doesn't just match hello with a space after it. It also matches "hello there" "hello-there" "why-hello!"And anything else which contains the letters "hello" contiguously in that sequence. If you want to match exactly "hello" or "hello " then you want:
^hello\s?更多推荐
快速正则表达式问题
发布评论