/    Sign up×
Bounties /Pin to ProfileBookmark

Javascript Regex

Hi there, anyone can help with the pattern in JS regex”More than two identical consecutive characters not allowed (e.g. 111,aaa). More than two sequential characters not allowed(e.g. 123, abc)”. Thanks in advance

to post a answer
JavaScript

2 Replies

Davinci•003 auto-replyRegular expressions (or regex) are a powerful tool for manipulating text and data. In JavaScript, regular expressions are also objects. These objects are created with the RegExp constructor, which takes a string as an argument and returns a regex object. The string passed to the constructor can be a simple pattern or a more complex expression.

For example, the following code creates a regex object that matches any string that contains the word "cat":

let catRegex = new RegExp('cat');

You can then use the regex object to search for matches in a string. For example, the following code searches for the word "cat" in the string "The cat in the hat":

let str = "The cat in the hat";
let result = catRegex.test(str);

// result is true

You can also use regex to search for more complex patterns. For example, the following code creates a regex object that matches any string that contains a sequence of digits:

let digitRegex = new RegExp('\d+');

You can then use the regex object to search for matches in a string. For example, the following code searches for a sequence of digits in the string "Code123":

let str = "Code123";
let result = digitRegex.test(str);

// result is true

For more information on using regex in JavaScript, please see the

Was this helpful?

Copy linkTweet thisAlerts:
@phil-macrofabMar 24.2023 — Hi,
\b(?:([a-zA-Z0-9])(?!\1))+\b
when applied to: aab aba aab aba baa baa 123 222 56789 AA ABC
would match: aba aba 123 56789 ABC
assuming word boundaries and alpha-numeric only.

a less restrictive:(?:([\s\S])(?!\1))+ which assumes nothing using the same above test string would match: ab aba , ab aba b, a b, a 123 , 2, 56789 , A ABC
@wordpreeauthorHi 111,aaa,123,abc (within one word boundaries, alpha-numeric ) not allowed. ab is okMar 26.2023
×

Success!

Help @wordpree spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...