lewpie
lewpie

Reputation: 99

Skip the first 3 leading characters using RegEX

I am looking for a RegEX that would match/select all but the first 3 characters of a string (including whitespace). That is, select from the 4th character onwards, and if there is no 4th (or 3rd, or 2nd) character, there will be no match.

EX1. Given String: "ABC COMPANY"

RegEX should match " Company"

EX2. Given String: "JASON'S PAINTING"

RegEX should match "ON'S PAINTING"

EX3. Given String "AB"

RegEX should not match anything.

I have been able to come up with an expression that would match only the first the characters ^.{3}\s*, but this is the invert of what I would need.

This is not being used in any programming language so I cannot use string manipulation. For context, this is using Oracle's Enterprise Data Quality RegEX Replace processor.

Thanks in advance.

Upvotes: 5

Views: 25876

Answers (2)

Maayan
Maayan

Reputation: 208

I'm a rookie with regex, but try: (?<=.{3}).+

The part within the parentheses is a positive lookbehind - it gives up the match and only return whether a match afterwords is possible or not. The .+ token means there have to be at least one character. If you know all the characters will be word characters (0-9 a-z A-Z and underscore) or a whitespace, I recommend replacing the later dot with [\w\s].

Upvotes: 2

Sabuj Hassan
Sabuj Hassan

Reputation: 39355

I don't know whether the Oracle's Enterprise Data Quality RegEX Replace processor supports the Lookaround or not. But Here is the usual regex if it supports:

(?<=^...)(.*)

Here using positive lookbehind (?<=^...) it is checking that the match is after the three characters from the begin.

Online Demo

Upvotes: 11

Related Questions