Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop regex capturing after double spaces

Tags:

regex

I'm trying to match the content of a string up to the occurrence of a double space (ignoring the case when the double space is after the autor/name identifier) or any other character different than A-Z or a single blank space, until the moment I came up with the following regular expression, although the \S does match anything except a blank space.

(AUTOR|NAME):?([A-Z ]\S)+


AUTOR:  LEANDRO LUCIANI  TAVARES -- This should match up to 'AUTOR:  LEANDRO LUCIANI'

AUTOR LEANDRO LUCIANI \TAVARES -- This should match up to 'AUTOR LEANDRO LUCIANI' discarding anything after the backslash

AUTOR       LEANDRO TAVARES -- This should match up to 'AUTOR       LEANDRO TAVARES'

Edit:

I am trying to run it on C# so it must be compatible with the .NET implementation of regular expressions.

Thanks in advance, Leandro Tavares

like image 581
Leandro Tavares Avatar asked Mar 03 '26 09:03

Leandro Tavares


2 Answers

What you are looking for is probably something like that:

(AUTOR|NAME)[\s:]\s*([A-Z]+( [A-Z]+)*)
like image 115
Casimir et Hippolyte Avatar answered Mar 05 '26 02:03

Casimir et Hippolyte


This PCRE works for me:

/(AUTOR|NAME):?\s*([A-Z ]+?)(?:  | \\|\\|$)/
like image 20
Allen Luce Avatar answered Mar 05 '26 03:03

Allen Luce



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!