正则表达式后跟日期,没有空格

时间:2015-05-25 15:10:13

标签: php regex regex-negation

我有以下几行:

fact prof 45883
factura PROF 46186
FACT.PROF:45126
FACT.PROF.NR.46069
FACTURA PROF. 46296
factura prof.46673
FAC PROFORMA PROF 46876
FACT 44046
FACT 46529
fact proforma nr 46229
FCT PROF:40365
PROF 44283
fact prof 46646
FACT PROF: 45666
fact PROF:45560
Factura proforma : 46059
FCT PROF 45108
fact. proforma nr.46180
FACTURA PROFORMA NR 43864 SI FACTURA PROFORMA NR 43865
PROF 46471
prof nr 42840
PROF. NR.45830
FAC. PROFORMA NR. 46373
fact prof 38518
f prof 45983
factura proforma 46753
factura  prof 46326
f prof 46645
f prof 43723
fact prof.nr 46227
factura proforma 41292
prof 45602
F.45026
FAC. PROFORMA: 43017
FACT 43198
FACT PROF 46284
fact proforma nr 45984
fact prof 46656
fact. nr. 45224
fact PROF:46282
prof 45826
PROFORMA 42801
fact prof 45579
FF 46105
FACTURA PROF 45237
factura proforma 43335
fact nr 43709
FACTURA PROF:46962
Seria PRO nr. 43712
SERIA PRO NR : 43099 
PROF 45515
Factura PROF : 45722
PROFORMA Seria PRO nr. 43051
PROF46215
PROF 45131
PROF460798wheels
proforma 43736
proforma 43642 si 38987
Factura 46690
Fproforma 416477
PROF   45608
factura numar 42995
PROF :43679
PROF:46801
Prof45066
PROF: 45613
Factura 45369
prof 46791
PROF 45198
prof 39970
Prof. 46039
Seria PROF NR 45273
fact. proforma 46446
PROF 46911
prof 45044
PROF: 45674
Proforma 46241
PROF: 43943
prof 43769
prof46611
PROFORMA NR 46635
prof. nr. 45597
PROF42088
FACTURA 44235
PROF 46024 SI 46156
proforma 46219
PROFORMA nr. 4712619.05.2015
Proforma 46333 
PROF  44961
PROF 43941
Prof:45303
prof44895
FACTURA 45199
proforma 46263/12.05.15 
PRPROF:46717

我需要从相应的字符串中提取数字。我创建了一个几乎涵盖所有案例的Reg-ex,但我有2个案例无法涵盖:

  1. 第一个是PROF460798轮,其中数字与公司名称(8轮)连接

  2. 第二个是PROFORMA nr。 4712619.05.2015,其中数字与日期连接。

  3. 有没有办法排除这些行或获得正确的数字?

    直到现在这是我的正则表达式:

    (?:prof|proforma|F|fact|PRO|factura)\s?\.?\s?(?:nr|numar)?\.?\s?:?\s?(\d+(?!\d\d\.\d{2}\.\d{4}))\s?(?:si)?\s?(\d+)?
    

    一些全文示例:

    Decontare -Platitor: COLCERIU LAURA-ELENA; RO20OTPV112004321192RO01-Beneficiar: SC DUMMY SRL; RO96RNCB0040124547320001; CODFISC 16296240-Detalii: /ROC/Fproforma 416477 din 14.05.15//RFB/16
    Decontare -Platitor: Aliman Samuel-lucian; RO61INGB2220999904092615-Beneficiar: DUMMY; RO96RNCB4090124247370001-Detalii: /ROC/PROF:46634/RFB/NONE.
    Decontare -Platitor: VLAD CAMBURU; RO61INGB2220999904092615-Beneficiar: DUMMY; RO61INGB2220999904092615-Detalii: /ROC/Factura PROF:43751vlad camburu//RFB/1
    Decontare -Platitor: CARP COSMIN; RO20OTPV112004321192RO01; CODFISC NA-Beneficiar: DUMMY; RO20OTPV112004323192RO01; CODFISC NA-Detalii: /ROC/PROF:46583                         Abonament servicii sportive dummy  Partener (65676301) 04/05   03/08
    

2 个答案:

答案 0 :(得分:3)

如果您需要的唯一内容是数字,您可以使用以下注册表:

/\d{5}/g

示例:

https://regex101.com/r/bA6vN4/1

修改

所以显然你只需要数字的前5位而不是整个字符串:

8wheels

https://regex101.com/r/bA6vN4/2

修改

这个应该这样做,当它们彼此相邻时,它会从数字中删除日期,并考虑到你的特殊/(?:proforma|PROFORMA|Proforma|factura|FACTURA|Factura|nr|NR|numar|NUMAR|prof|Prof|PROF|fact|FACT|fac|FAC|FCT|si|SI|F)(?:\s?|\.?|:?)*(\d+(?=8wheels|(?:(\d{2}\.\d{2}\.\d{4})))|\d+)/gm 案例:

{{1}}

https://regex101.com/r/fJ3sN6/4

答案 1 :(得分:0)

var Dialog = React.createClass({
    render: function() {
        return <div> {this.props.text} </div>
    }
});

var Page = React.createClass({
    handleClick: function() {
        this.props.onDialogChange(React.createElement.bind(null, Dialog, {text: 'hello world!'}))
    },
    render: function() {
    return (
      <div onClick = {this.handleClick}>
        Click me!
      </div>
    );
 }
});

var App = React.createClass({
  getInitialState: function() {
    return {dialogCreator: null};
  }, 
  handleDialogChange: function(dialogCreator) {
    this.setState({dialogCreator: dialogCreator});
  },
  render: function {
    return (
      <div>
        { this.state.dialogCreator ? this.state.dialogCreator() : null }
        <Page onDialogChange = {this.handleDialogChange} />
      </div>
    );
  }
});

你可以尝试一下。参见演示。

https://regex101.com/r/nM7nT5/8