A
A
Alexey Bespalov2022-02-03 18:12:55
Regular Expressions
Alexey Bespalov, 2022-02-03 18:12:55

How to choose a word so that it is not between other words?

I need to replace all expressions of the word "If" except when it is inside a word.
IfOtherwise - we do not replace
SomethingIfNotThat - we do not replace

And these we replace
If Not
If;
(If)
If=
=If
etc.

I can't figure out the regular expression.
Everything seems to be simple, but for example this [^A-z] If [^A-z] captures spaces and the service characters themselves, but only the word is needed, everything else should remain in its place.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2022-02-03
@FreeArcher

Something like this, but it's like this:(?<=[^А-яёЁ]|^)Если(?=[^А-яёЁ]|$)

D
Dmitry Belyaev, 2022-02-03
@bingo347

/\bЕсли\b/So?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question