Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • as I said in the post, the word is not important for my question. For example, I have this regex (?<=\b|_)sUs[^\W_]*(?=\b|_) which matches a word with the prefix sUs. The question was, can I replace the anchor expressions (?<=\b|_) and (?=\b|_) with some other expression that uses ^ and $ symbols AND does not use \b, but achieves the exact same result Commented Jan 17, 2024 at 18:52
  • Not using \b for no reason is stupid. (Implementation-dependent is not a reason, since \w is just as implementation-dependent.) However, (?<=\b|_) is a variable-length lookbehind, and that's not well supported. You could use (?<! [^\W_] ) sUs [^\W_]*. Answer updated. Commented Jan 17, 2024 at 19:17
  • I tested your updated answer against my text file, and it appears to be equivalent to my initial expression, and it indeed refrains from using \b. The idea about ^ and $ is a misunderstanding on OP (me) part. I guess my whole text file is counted as one large string, and ^ matches the beginning, and $ the end. Commented Jan 17, 2024 at 19:20
  • 1
    If you think ^ and $ aren't implementation-specific, you're wrong. They vary more than \b Commented Jan 17, 2024 at 19:23