0

i have a this strings

01 - Il visitatore - Lia and me II

i write this regex

(\d*).-?.-\s

but match only number. as a result I would

Group1: 01 
Group2: Il visitatore misterioso

2 Answers 2

1

If you have access to a programming code, you could easily split the string with "space"-"hyphen"-"space", and get the necessary items.

With a regex, you may use

^(\d+)\s*-\s*([^-]+)\s

See the regex demo

Details:

  • ^ - start of string
  • (\d+) - Group 1 capturing 1 or more digits
  • \s*-\s* - a hyphen enclosed with 0+ whitespaces
  • ([^-]+) - Group 2 capturing 1+ chars other than -, as many as possible (the + quantifier is greedy)
  • \s - a whitespace
Sign up to request clarification or add additional context in comments.

Comments

0

Hope this helps!

var string = '01 - Il visitatore misterioso - Mia and me II';
var regex = /^(\d{2})\s\-\s([\w\s]+)\-[\w\s]+$/;
var matches = regex.exec(string);

console.log('Group 1:', matches[1])
console.log('Group 2:', matches[2])

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.