Regex match sequence more than once

yanivps

How come for something that simple I can't find an answer after looking one hour in the internet?

I have this sentence:

HeLLo woRLd HOw are YoU

I want to capture all groups that consist of two following capital letters

[A-Z]{2}

The regex above works but capture only LL (the first two capital letters) while I want LL in one group and in the other groups also RL HO

npinti

Most regular expression engines expose some way to make your expression global. This means that your expression will applied multiple times. This global flag is usually denoted with the /g marker at the end of your expression. This is your regular expression without the /g flag, while this is what happens when you apply said flag.

Different languages expose such functionality differently, in C# for instance, this is done through the Regex.Matches syntax. In Java, you use while(matcher.find()), which keeps providing sub strings which match the pattern provided.

EDIT: I am not a Python person, but judging from the example available here, you could do something like so:

it = re.finditer(r"[A-Z]{2}", "HeLLo woRLd HOw are YoU")
for match in it:
    print "'{g}' was found between the indices {s}".format(g=match.group(), s=match.span())

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

prevent the same request done more than once

분류에서Dev

prevent the same request done more than once

분류에서Dev

Link one model more than once

분류에서Dev

Saving more than one entity at once

분류에서Dev

How to run a thread more than once in python

분류에서Dev

python watchdog runs more than once

분류에서Dev

Same user added more than once in Database

분류에서Dev

Is necessary digitally sign a document more than once?

분류에서Dev

Regex how to match the string at end of sequence?

분류에서Dev

Regex replacing more than I want

분류에서Dev

Why can't a jQuery object be appended more than once?

분류에서Dev

MySQL ignore query results with column that appears more than once

분류에서Dev

jquery slideshow won't cycle through more than once

분류에서Dev

Check if word occurs more than once in a text document

분류에서Dev

How to remove all lines that occur more than once

분류에서Dev

SQL error: Table name specified more than once

분류에서Dev

More than one type at once in JSON-LD notation

분류에서Dev

Parsing XML file more than once and merging the results together

분류에서Dev

Parsing XML file more than once and merging the results together

분류에서Dev

SQL Server CLR Library Stored Procedure static object instantiated more than once

분류에서Dev

How do I prevent button code from running twice if the user clicks more than once in C#?

분류에서Dev

Ember.js: How do I prevent this property observer from being hit more than once?

분류에서Dev

Accessing a SessionScoped bean from another SessionScoped bean more than once in same session creates a new instance

분류에서Dev

Detect all incidences of "Parameter was used more than once" in Pl/pgSQL functions

분류에서Dev

can't retrieve css properties from popup.js elements more than once

분류에서Dev

Error on getting authorization URL more than once in Twitter4j

분류에서Dev

How to predict more than one value for each sequence in Keras? LSTM Layers

분류에서Dev

why is media player starts more than once and media player won't stop in button click which started at on create?

분류에서Dev

Regex to match "a string of length less than X resides between two ">" symbols"

Related 관련 기사

  1. 1

    prevent the same request done more than once

  2. 2

    prevent the same request done more than once

  3. 3

    Link one model more than once

  4. 4

    Saving more than one entity at once

  5. 5

    How to run a thread more than once in python

  6. 6

    python watchdog runs more than once

  7. 7

    Same user added more than once in Database

  8. 8

    Is necessary digitally sign a document more than once?

  9. 9

    Regex how to match the string at end of sequence?

  10. 10

    Regex replacing more than I want

  11. 11

    Why can't a jQuery object be appended more than once?

  12. 12

    MySQL ignore query results with column that appears more than once

  13. 13

    jquery slideshow won't cycle through more than once

  14. 14

    Check if word occurs more than once in a text document

  15. 15

    How to remove all lines that occur more than once

  16. 16

    SQL error: Table name specified more than once

  17. 17

    More than one type at once in JSON-LD notation

  18. 18

    Parsing XML file more than once and merging the results together

  19. 19

    Parsing XML file more than once and merging the results together

  20. 20

    SQL Server CLR Library Stored Procedure static object instantiated more than once

  21. 21

    How do I prevent button code from running twice if the user clicks more than once in C#?

  22. 22

    Ember.js: How do I prevent this property observer from being hit more than once?

  23. 23

    Accessing a SessionScoped bean from another SessionScoped bean more than once in same session creates a new instance

  24. 24

    Detect all incidences of "Parameter was used more than once" in Pl/pgSQL functions

  25. 25

    can't retrieve css properties from popup.js elements more than once

  26. 26

    Error on getting authorization URL more than once in Twitter4j

  27. 27

    How to predict more than one value for each sequence in Keras? LSTM Layers

  28. 28

    why is media player starts more than once and media player won't stop in button click which started at on create?

  29. 29

    Regex to match "a string of length less than X resides between two ">" symbols"

뜨겁다태그

보관