1

I am looking for a regex that will match the first line, but not the second. This is what I have /^github.com\/[^\\\n]+$/

github.com/reggi
github.com/reggi/example

https://regexr.com/3ld7o

var patternA = /^github.com\/[^\\\n]+$/
var patternB = /^github\.com\/.+/
var patternC = /^github.com\/[^\/\n]+$/

var examples = function (pattern) {
  return [
    !!'github.com/reggi/genesis/soup'.match(pattern),
    !!'github.com/reggi/genesis'.match(pattern),
    !!'github.com/reggi'.match(pattern),
  ]
}

console.log(examples(patternA))
console.log(examples(patternB))
console.log(examples(patternC))

1
  • !!'...'.match(pattern) -> pattern.test('...') Commented Feb 27, 2018 at 4:30

2 Answers 2

1
^github.com\/[^\/\n]+$

I think you just had the wrong type of slash escaped.

https://regexr.com/3ld8v

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

2 Comments

If that was the case, it would not select github.com/reggi/genesis/soup regexr.com/3ld8j
I see. I thought you were concerned with matching on separate lines. Edited answer.
0

The pattern /^github\.com\/.+/ is enough for your need (remember to uncheck m - multiline when you test with regexr.com).

https://regexr.com/3ld7u

1 Comment

If that was the case, it would not select github.com/reggi/genesis/soup regexr.com/3ld8j

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.