-4

I need logical AND in regex.

something like

real AND substance (or simply subs)

agree with only following string (in any order)

Real Substance

but not

Real Substance External

Real substance group

I need to use the REGEX in SAP ABAP. Please help.

  • 2
    What you need is not clear. Please post an [MCVE](https://stackoverflow.com/help/mcve). – PJProudhon Feb 02 '18 at 08:07
  • Possible duplicate of [Regular Expressions: Is there an AND operator?](https://stackoverflow.com/questions/469913/regular-expressions-is-there-an-and-operator) – ctwheels Feb 02 '18 at 19:53

2 Answers2

2

Alexander's answer assumes that Regular Expressions in ABAP accept the modifiers *? and ?? but they don't, so simply use * and ? instead, as follows:

^(?:real\s*subs(?:tance)?|subs(?:tance)?\s*real)$
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
1

UPDATE TO ALLOW for "subs"

Naive approach would be:

^(?:real\s*?subs(?:tance)??|subs(?:tance)??\s*?real)$

Try it here: https://regex101.com/r/7RznVy/3

Don't know if your tool allows flags; use "i" to make case-insensitive.

I recommend you to read the classic: Mastering Regular Expressions by Jeffrey Friedl

Alexander
  • 313
  • 3
  • 10