寻找正则表达式以大写字母为基础拆分字符串

时间:2023-01-25 09:22:25

Looking for regex solution for following scenaio:

寻找关注sceaio的正则表达式解决方案:

I have strings, which i have to split on the upper case basis but consecutive uppercase parts should not get split.

我有字符串,我必须在大写的基础上拆分,但连续的大写部分不应该拆分。

For example : if the input is

例如:如果输入是

DisclosureOfComparativeInformation

O/p should be

O / p应该是

Disclosure Of Comparative Information

But consecutive uppercase should not get split.

但连续的大写不应该分裂。

GAAP should not result in G A A P.

GAAP不应导致G A A P.

How to find the particular pattern and insert space?

如何找到特定的图案并插入空间?

Thanx

7 个解决方案

#1


7  

Try -

var subjectString = "DisclosureOfComparativeInformation";
var resultString = Regex.Replace(subjectString, "([a-z])([A-Z])", "$1 $2");

#2


1  

Try this regex:

试试这个正则表达式:

[a-z](?=[A-Z])

With this call to replace:

通过此次调用来替换:

regex.Replace(toMatch, "$& ")

For more information on the special replacement symbol "$&", see http://msdn.microsoft.com/en-us/library/ewy2t5e0.aspx#EntireMatch

有关特殊替换符号“$&”的详细信息,请参阅http://msdn.microsoft.com/en-us/library/ewy2t5e0.aspx#EntireMatch

#3


1  

((?<=[a-z])[A-Z]|[A-Z](?=[a-z]))

replace with

" $1"

In a second step you'd have to trim the string.

在第二步中,您必须修剪字符串。

check out this link also......

查看此链接还......

Regular expression, split string by capital letter but ignore TLA

正则表达式,用大写字母拆分字符串但忽略TLA

#4


0  

Using regex solutions to look for strings where something is not true tends to become unrecognizable. I'd recommend you go through your string in a loop and split it accordingly without using regexp.

使用正则表达式解决方案来寻找不真实的字符串往往变得无法识别。我建议你在循环中浏览你的字符串并相应地拆分它而不使用正则表达式。

#5


0  

[A-Z]{1}[a-z]+

will split as follows if replaced with match + space

如果用match + space替换,将按如下方式拆分

DisclosureOfComparativeInformation -> Disclosure Of Comparative Information

DisclosureOfComparativeInformation - >披露比较信息

GAPS -> GAPS

差距 - >差距

SOmething -> SOmething This one may be undesirable

SOmething - > SOmething这个可能是不受欢迎的

alllower -> alllower

alllower - > alllower

#6


0  

Split and Join:

拆分和加入:

string.Join(" ", Regex.Split("DisclosureOfComparativeInformation", @"([A-Z][a-z]*)"))

#7


0  

In Perl this should work:

在Perl中这应该工作:

str =~ s/([A-Z][a-z])/ \1/g;

The parenthesis around the two character sets save the match for the "\1" (number one) later.

两个字符集周围的括号将稍后保存“\ 1”(数字1)的匹配。

#1


7  

Try -

var subjectString = "DisclosureOfComparativeInformation";
var resultString = Regex.Replace(subjectString, "([a-z])([A-Z])", "$1 $2");

#2


1  

Try this regex:

试试这个正则表达式:

[a-z](?=[A-Z])

With this call to replace:

通过此次调用来替换:

regex.Replace(toMatch, "$& ")

For more information on the special replacement symbol "$&", see http://msdn.microsoft.com/en-us/library/ewy2t5e0.aspx#EntireMatch

有关特殊替换符号“$&”的详细信息,请参阅http://msdn.microsoft.com/en-us/library/ewy2t5e0.aspx#EntireMatch

#3


1  

((?<=[a-z])[A-Z]|[A-Z](?=[a-z]))

replace with

" $1"

In a second step you'd have to trim the string.

在第二步中,您必须修剪字符串。

check out this link also......

查看此链接还......

Regular expression, split string by capital letter but ignore TLA

正则表达式,用大写字母拆分字符串但忽略TLA

#4


0  

Using regex solutions to look for strings where something is not true tends to become unrecognizable. I'd recommend you go through your string in a loop and split it accordingly without using regexp.

使用正则表达式解决方案来寻找不真实的字符串往往变得无法识别。我建议你在循环中浏览你的字符串并相应地拆分它而不使用正则表达式。

#5


0  

[A-Z]{1}[a-z]+

will split as follows if replaced with match + space

如果用match + space替换,将按如下方式拆分

DisclosureOfComparativeInformation -> Disclosure Of Comparative Information

DisclosureOfComparativeInformation - >披露比较信息

GAPS -> GAPS

差距 - >差距

SOmething -> SOmething This one may be undesirable

SOmething - > SOmething这个可能是不受欢迎的

alllower -> alllower

alllower - > alllower

#6


0  

Split and Join:

拆分和加入:

string.Join(" ", Regex.Split("DisclosureOfComparativeInformation", @"([A-Z][a-z]*)"))

#7


0  

In Perl this should work:

在Perl中这应该工作:

str =~ s/([A-Z][a-z])/ \1/g;

The parenthesis around the two character sets save the match for the "\1" (number one) later.

两个字符集周围的括号将稍后保存“\ 1”(数字1)的匹配。