1

I have a data one on each line in a file as below

BMT.PQ
DMZ.IV
VLD.Q
WPS.T

I am looking for a regex to split out into two categories of output

One where starting letter of the data is between A to M

and other

where starting letter of the data is from N to Z

I tried this

[A-M].* for getting first half of data with first beginning letter from A to M

and i was expecting a result/regex text match of

only :

BMT.PQ 
DMZ.PQ

but it also gave a match for

LD.Q which was incorrect for me.

I even unsuccessfully tried [(A-M)(A-M)(A-M)].*

Basically i want to split based on starting letter in the data. One half for data beginning with letters from A to M and second half for data beginning with letter N to Z.

4

2 に答える 2

1

あなたは近くにいます、あなたが必要とするの^は文字列の始まりと文字列$の終わりのために追加することだけです。

^[A-M].*$

^[N-Z].*$

マルチラインモードを有効にしてください。マルチラインモード(通常はmフラグ)では^$行の開始と終了をそれぞれ検出できます。

于 2012-10-25T14:43:48.930 に答える
0

カラット記号は、検索/一致する文字列の開始を表します。おそらく必要な 2 つの正規表現は次のとおりです。

^[A-M]

^[N-Z]
于 2012-10-25T14:41:41.860 に答える