Regex for Word space Word space Word ....

Started by Shaozhong SHIover 4 years ago9 messagesgeneral
Jump to latest
#1Shaozhong SHI
shishaozhong@gmail.com

Is there any regex for Word space Word space Word and more?

Regards,

David

#2Shaozhong SHI
shishaozhong@gmail.com
In reply to: Shaozhong SHI (#1)
Re: Regex for Word space Word space Word ....

I tried nested regex '[[A-Z][a-z] ]+[[A-Z][a-z]]' but it did not work.

Regards,

David

On Tue, 23 Nov 2021 at 09:58, Shaozhong SHI <shishaozhong@gmail.com> wrote:

Show quoted text

Is there any regex for Word space Word space Word and more?

Regards,

David

#3Hans Schou
hans.schou@gmail.com
In reply to: Shaozhong SHI (#2)
Re: Regex for Word space Word space Word ....

On Tue, Nov 23, 2021 at 11:51 AM Shaozhong SHI <shishaozhong@gmail.com>
wrote:

I tried nested regex '[[A-Z][a-z] ]+[[A-Z][a-z]]' but it did not work.

[A-Z][a-z]+ +[A-Z][a-z]+
will match 'Hello World', but not 'Hello world'. Is that what you want?

Try this instead
[A-Za-z]+ +[A-Za-z]+

And try also this editor to learn regex
https://regex101.com/

./hans

#4Shaozhong SHI
shishaozhong@gmail.com
In reply to: Hans Schou (#3)
Re: Regex for Word space Word space Word ....

It only matches First Street from 'My First Street'.

I was trying to make it to match words starting capital letter only.

Regards,
David

On Tue, 23 Nov 2021 at 10:59, chlor <hans.schou@gmail.com> wrote:

Show quoted text

On Tue, Nov 23, 2021 at 11:51 AM Shaozhong SHI <shishaozhong@gmail.com>
wrote:

I tried nested regex '[[A-Z][a-z] ]+[[A-Z][a-z]]' but it did not work.

[A-Z][a-z]+ +[A-Z][a-z]+
will match 'Hello World', but not 'Hello world'. Is that what you want?

Try this instead
[A-Za-z]+ +[A-Za-z]+

And try also this editor to learn regex
https://regex101.com/

./hans

#5Saurabh Agrawal
mail@saurabhagrawal.net
In reply to: Shaozhong SHI (#4)
Re: Regex for Word space Word space Word ....

I was trying to make it to match words starting capital letter only.

Does this work? https://regex101.com/r/nf4HCN/1

Show quoted text

Regards,
David

On Tue, 23 Nov 2021 at 10:59, chlor <hans.schou@gmail.com> wrote:

On Tue, Nov 23, 2021 at 11:51 AM Shaozhong SHI <shishaozhong@gmail.com>
wrote:

I tried nested regex '[[A-Z][a-z] ]+[[A-Z][a-z]]' but it did not work.

[A-Z][a-z]+ +[A-Z][a-z]+
will match 'Hello World', but not 'Hello world'. Is that what you want?

Try this instead
[A-Za-z]+ +[A-Za-z]+

And try also this editor to learn regex
https://regex101.com/

./hans

#6Andreas Joseph Krogh
andreas@visena.com
In reply to: Shaozhong SHI (#4)
Re: Regex for Word space Word space Word ....

På tirsdag 23. november 2021 kl. 12:25:29, skrev Shaozhong SHI <
shishaozhong@gmail.com <mailto:shishaozhong@gmail.com>>:

It only matches First Street from 'My First Street'.

I was trying to make it to match words starting capital letter only.

You'll want to include unicode-characters, which [A-Z] approach doesn't handle
well.

How about:

select regexp_matches('Åge is a Man', E'[[:upper:]]\\w+', 'g');

--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
andreas@visena.com <mailto:andreas@visena.com>
www.visena.com <https://www.visena.com&gt;
<https://www.visena.com&gt;

#7tomas@tuxteam.de
tomas@tuxteam.de
In reply to: Shaozhong SHI (#1)
Re: Regex for Word space Word space Word ....

On Tue, Nov 23, 2021 at 09:58:00AM +0000, Shaozhong SHI wrote:

Is there any regex for Word space Word space Word and more?

It isn't very clear what you want to achieve. From the other mails in
this thread I understand that your words start with an uppercase char
and continue with lowercase chars. Is that right?

You want exactly one space between words, or more than one?

What is this "...and more"? Arbitrary repetitions?

Which kind of regular expressions do you want to use? POSIX?

If all the answers to the above are "yes", you might try something like

"(?:[[:upper:]][[:lower:]]*[[:space:]]+)*[[:upper:]][[:lower:]]*"

(Caveat: untested). This would match a single word or more than one
word, separated by one or more spaces, where a word starts with one
upper-case character and continues with zero or more lowercases.

HTH
- t

#8David G. Johnston
david.g.johnston@gmail.com
In reply to: Shaozhong SHI (#1)
Re: Regex for Word space Word space Word ....

On Tue, Nov 23, 2021 at 2:58 AM Shaozhong SHI <shishaozhong@gmail.com>
wrote:

Is there any regex for Word space Word space Word and more?

What problem are you actually trying to solve? You may find it easier to
simply split your string on space and then do tests on elements of the
resultant array.

David J.

#9Shaozhong SHI
shishaozhong@gmail.com
In reply to: David G. Johnston (#8)
Re: Regex for Word space Word space Word ....

Hi, David J,
Any good example of doing test on array?

Regards, David

On Tuesday, 23 November 2021, David G. Johnston <david.g.johnston@gmail.com>
wrote:

Show quoted text

On Tue, Nov 23, 2021 at 2:58 AM Shaozhong SHI <shishaozhong@gmail.com>
wrote:

Is there any regex for Word space Word space Word and more?

What problem are you actually trying to solve? You may find it easier to
simply split your string on space and then do tests on elements of the
resultant array.

David J.