pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Regex for Word space Word space Word ....
9+ messages / 6 participants
[nested] [flat]

* Regex for Word space Word space Word ....
@ 2021-11-23 09:58  Shaozhong SHI <shishaozhong@gmail.com>
  0 siblings, 3 replies; 9+ messages in thread

From: Shaozhong SHI @ 2021-11-23 09:58 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

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

Regards,

David

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Regex for Word space Word space Word ....
@ 2021-11-23 10:51  Shaozhong SHI <shishaozhong@gmail.com>
  parent: Shaozhong SHI <shishaozhong@gmail.com>
  2 siblings, 1 reply; 9+ messages in thread

From: Shaozhong SHI @ 2021-11-23 10:51 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

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:

> Is there any regex for Word space Word space Word and more?
>
> Regards,
>
> David
>

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Regex for Word space Word space Word ....
@ 2021-11-23 10:59  chlor <hans.schou@gmail.com>
  parent: Shaozhong SHI <shishaozhong@gmail.com>
  0 siblings, 1 reply; 9+ messages in thread

From: chlor @ 2021-11-23 10:59 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Regex for Word space Word space Word ....
@ 2021-11-23 11:25  Shaozhong SHI <shishaozhong@gmail.com>
  parent: chlor <hans.schou@gmail.com>
  0 siblings, 2 replies; 9+ messages in thread

From: Shaozhong SHI @ 2021-11-23 11:25 UTC (permalink / raw)
  To: chlor <hans.schou@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

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:

> 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
>
>

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Regex for Word space Word space Word ....
@ 2021-11-23 12:08  Saurabh Agrawal <mail@saurabhagrawal.net>
  parent: Shaozhong SHI <shishaozhong@gmail.com>
  1 sibling, 0 replies; 9+ messages in thread

From: Saurabh Agrawal @ 2021-11-23 12:08 UTC (permalink / raw)
  To: Shaozhong SHI <shishaozhong@gmail.com>; +Cc: chlor <hans.schou@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>

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

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



>
> 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
>>
>>

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Regex for Word space Word space Word ....
@ 2021-11-23 12:32  Andreas Joseph Krogh <andreas@visena.com>
  parent: Shaozhong SHI <shishaozhong@gmail.com>
  1 sibling, 0 replies; 9+ messages in thread

From: Andreas Joseph Krogh @ 2021-11-23 12:32 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org


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;
 <https://www.visena.com;

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Regex for Word space Word space Word ....
@ 2021-11-23 13:53  tomas@tuxteam.de
  parent: Shaozhong SHI <shishaozhong@gmail.com>
  2 siblings, 0 replies; 9+ messages in thread

From: tomas@tuxteam.de @ 2021-11-23 13:53 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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

Attachments:

  signature.asc (application/pgp-signature, 194B) download

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Regex for Word space Word space Word ....
@ 2021-11-23 15:31  David G. Johnston <david.g.johnston@gmail.com>
  parent: Shaozhong SHI <shishaozhong@gmail.com>
  2 siblings, 1 reply; 9+ messages in thread

From: David G. Johnston @ 2021-11-23 15:31 UTC (permalink / raw)
  To: Shaozhong SHI <shishaozhong@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

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.

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Regex for Word space Word space Word ....
@ 2021-11-23 17:13  Shaozhong SHI <shishaozhong@gmail.com>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 9+ messages in thread

From: Shaozhong SHI @ 2021-11-23 17:13 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

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:

> 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.
>

^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2021-11-23 17:13 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-11-23 09:58 Regex for Word space Word space Word .... Shaozhong SHI <shishaozhong@gmail.com>
2021-11-23 10:51 ` Shaozhong SHI <shishaozhong@gmail.com>
2021-11-23 10:59   ` chlor <hans.schou@gmail.com>
2021-11-23 11:25     ` Shaozhong SHI <shishaozhong@gmail.com>
2021-11-23 12:08       ` Saurabh Agrawal <mail@saurabhagrawal.net>
2021-11-23 12:32       ` Andreas Joseph Krogh <andreas@visena.com>
2021-11-23 13:53 ` tomas@tuxteam.de
2021-11-23 15:31 ` David G. Johnston <david.g.johnston@gmail.com>
2021-11-23 17:13   ` Shaozhong SHI <shishaozhong@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox