English 中文(简体)
经常表达、麻烦!
原标题:Regular expressions, what a trouble!
  • 时间:2010-12-02 09:24:05
  •  标签:
  • regex
  • plsql

我需要你帮助解决这一问题。

我表示,我无法使用Oracle PL/SQL的再大表述,但我保证,我会研究他们。

Please suppose you have a table with a column called MY_COLUMN of type VARCHAR2(4000).

该表层居民如下:

Description of first no.;00123457;Description of 2nd number;91399399119;Third Descr.;13456

你们可以看到,这些扼杀是由几个数字(可能从零开始)和扼杀(含有所有字母数字特征,也含有 do、,、/、/等):

Description1;Number1;Description2;Number2;Description3;Number3;......;DescriptionN;NumberN

当然,N并不为人所知,这意味着每个记录中的夫妇人数可能因记录而异。

In every couple the first element is always the number (which may begin with zero, I repeat), and the second element is the string.

野外分离者是ALWAYS半殖民地(;)。

我将数字改变如下:

00123457 ===> 001-23457
91399399119 ===> 913-99399119
13456 ===> 134-56

这意味着,在人数的前三位数之后,我需要带一个 d子“-”。

我如何利用定期表达来实现这一点?

事先感谢你的友好合作!

最佳回答

我并不了解Oracle/PL/SQL,但我可以提供以下文件:

([[:digit:]]{3})([[:digit:]]+)

至少与四位数相匹配,并记住头三位数与其余部分分开。

RegexBuddy 由此形成以下法典:

DECLARE
    result VARCHAR2(255);
BEGIN
    result := REGEXP_REPLACE(subject,  ([[:digit:]]{3})([[:digit:]]+) ,  1-2 , 1, 0,  c );
END;

如果你需要确保这些数字总是以<条码>直接相重;

(^|;)([[:digit:]]{3})([[:digit:]]+)(;|$)

但是,如果两个数字可以直接对应(12345;678<)只与第一个数字相匹配,则不会奏效。 如果这不是问题,则使用

result := REGEXP_REPLACE(subject,  (^|;)([[:digit:]]{3})([[:digit:]]+)(;|$) ,  12-34 , 1, 0,  c );
问题回答

暂无回答




相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签