0

I have a regular expression like

f[u\W&&[^\s,]][c\W&&[^\s,]]?k(?!(uoka|uyama|ushima|nowledge))

to find some f words, but it works in Java, but it cannot find the f words in Javascript, what's the difference for this expression in Java and javascript? and how to solve it, anyone can give me an idea, thanks.

I tried to change "]]" to "]", seems it works in Javascript, but I don't know why, the bracket is not paired in this way

2
  • 1
    You need to provide examples of the data you're working with and expected results Commented Nov 30, 2022 at 5:15
  • 4
    There is no && class intersection operator in JavaScript. Commented Nov 30, 2022 at 5:21

1 Answer 1

1

JavaScript does not support the class intersection operator &&.

So in particular, JavaScript does not deal with && in that way when it parses [u\W&&[^\s,]]. Java interprets this as:

Match a character that is either u or a non-alphanumerical character, but not a white-space or a comma.

You can convert this by using a negative look ahead for the "but not..." part: (?![\s,])[u\W]. The same workaround will work for [c\W&&[^\s,]].

So that leads to this regex:

f(?![\s,])[u\W](?![\s,])[c\W]?k(?!(uoka|uyama|ushima|nowledge))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.