hotshotiguana
hotshotiguana

Reputation: 1560

Multiple Capture Groups While Ignoring a Single Character

I have a string of random characters between A and z, such as tahbAwgubsuregbbu and I can easily capture between {1,n} characters before a s with ([A-z]{1,8})s, but now I am trying to ignore a single (or multiple characters) before the s is matched. For example in the string above, I want to exclude any w characters. I understand I can't "jump" over the w with a capture group and return tahbAgub, but could I create two capture groups where the concatenation of those two groups is {1,n} characters, such as 1. tahbA 2. gub?

Regex101 Example

Upvotes: 0

Views: 51

Answers (1)

Shafizadeh
Shafizadeh

Reputation: 10340

Try this:

/(.{0,8})?w(.{0,8})?s/

Online Demo


According to this comments, maybe you need to split your string. Something like this:

var str = "tftftfwtahbAwgubsuregbbu";
var res = str.split(/w|s/);
document.write(res);

Upvotes: 2

Related Questions