benaze
benaze

Reputation: 21

Exclude one character, exclude one space, then 4 spaces

I want to match this: exclude one character, exclude one space, then 4 spaces

here is what I tried but does not work

[^a-z0-9]{1}[^ ]{1}[ ]{4}

Debuggex Demo

I just want the 4 spaces, but before those 4 spaces there should be one character and one space, I don't know if I can

Upvotes: 0

Views: 62

Answers (4)

Tom Wyllie
Tom Wyllie

Reputation: 2085

For increased portability (look-behinds aren't supported everywhere), readability, and simplicity, try this regex.

(?:\w\s)(\s{4})

The first matching group will be your spaces as desired.

Upvotes: 0

Valdi_Bo
Valdi_Bo

Reputation: 31011

You wrote exclude, but I suppose you want to:

  • skip one char (a letter of number),
  • skip one space (after the just mentioned letter),
  • skip (or maybe catch) another 4 spaces,
  • catch the rest of the source text.

If this is the case, use the following regex:

[a-z0-9] ([ ]{4})(.*)

The four spaces (after initial char and space) will be in capture group #1 and the rest of the text will be in capture group #2.

Upvotes: 0

Toto
Toto

Reputation: 91518

If I well understand your need, this will do the job:

(?<=\w ) {4}

This is matching 4 spaces preceeded by an alphanumeric character and a space

Upvotes: 1

Oleksii Filonenko
Oleksii Filonenko

Reputation: 1653

This regex matches four spaces if they're preceeded by a lowercase letter/digit and one space.

(?<=[a-z0-9] ) {4}

Regex101 demo

Upvotes: 0

Related Questions