RegEx to match acronyms

前端 未结 3 1101
旧时难觅i
旧时难觅i 2021-01-16 10:24

I am trying to write a regular expression that will match values such as U.S., D.C., U.S.A., etc.

Here is what I have so far -

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-16 11:23

    Try (?:[a-zA-Z]\.){2,}

    ?: (non-capturing group) is there because you want to omit capturing the last iteration of the repeated group.

    For example, without ?:, 'U.S.A.' will yield a group match 'A.', which you are not interested about.

提交回复
热议问题