12

I want to match all characters after 8th character. And not include first 8!

I need exactly a regular expression cause a framework (Ace.js) requires a regexp, not a string. So, this is not an option:

var substring = "123456789".substr(5);

Can I match everything after nth character using regex in JavaScript?

Updates: I can't call replace(), substring() etc because I don't have a string. The string is known at run time and I don't have access to it. As I already said above the framework (Ace.js) asks me for a regex.

7
  • 2
    Why don't you use .{8} in front of the rest of your regex? Commented Dec 9, 2013 at 16:36
  • 1
    You can't. This would require a lookbehind assertion which javascript doesn't support. Commented Dec 9, 2013 at 16:46
  • @thg435, yes, I've read about that. So, there is no other way? Commented Dec 9, 2013 at 16:47
  • @AlekseiChepovoi: I'd look into their source code how they're using the regex. Is it always match(...)[0]? Commented Dec 9, 2013 at 16:50
  • @thg435, to create custom highlight mode github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode I need to pass regex to it and I'm unable to modify their source code. Ho could I? Suppose I will need to reference it from cdn. Commented Dec 9, 2013 at 17:03

2 Answers 2

21
(?<=^.{8}).* 

will match everything after the 7th position. Matches 89 in 0123456789

or IJKLM in ABCDEFGHIJKLM

etc

Sign up to request clarification or add additional context in comments.

Comments

5
console.log("123456789".match(/^.{8}(.*)/)[1])

1 Comment

/.{8}/ this selects a whole string if it's length >= 8. Check my question again please. I don't have access to the string, I need a regex, so I'm unable to use match(), subtr() or other methods

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.