0

In a weird case of mine, I cannot use the built-in regexp in js when I try to inject js to WebView.

What could be my second best thing to use? I basically use regexp to detect:

  • line-feed(someString.match(/\n/))

  • cartridge return(someString.match(/\r/))

  • split string into words(manyWords.split(/\s+/))

But other ways to achieve regexps without js built-in regexp will be appreciated as well.

3
  • 3
    Please show us the exact problem you are trying to solve. Commented Mar 29, 2020 at 5:38
  • 1
    why not use 3rd party lib like github.com/aaditmshah/regex Commented Mar 29, 2020 at 5:39
  • 1
    what exactly is the use case again? Perhaps it'd help you and us if you elaborate? Your previous post is as opaque as this one... Commented Mar 29, 2020 at 5:51

1 Answer 1

1

Use javascript's built-in string.prototype.indexOf and string.prototype.split, there's really no need for regex for those cases.

For line feed you can use someString.indexOf('\n') > -1

For cartridge return you can use someString.indexOf('\r') > -1

For splitting to words you can use manyWords.split(' ')

Incase you want the split a string that contains line breaks to words, you need to nest the split like this: manyWords.split('\n').flatMap(function(line) { return line.split(' ');});

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.