Get string before with regex

0

I need to make a regex for an application from which I need to remove a certain combination of characters from within a string. Explaining the problem better.

I have a string that returns from the database, something like this:

EVENTDATE:10/10/2015|*EDITAR_EVENTDATE:IwCalendar|EVENTTIME_INI:12:00|EVENTTIME_END:13:00|RANKINGHC:0|ALERGIAS:0|QUAIS_ALERGIAS:|INFECCAO:0|DATA_INFEC:|SITIO:0|QUADROCLINICO:|ASPECTO:0| ...

In this string I have values like this:

*EDITAR_EVENTDATE:IwCalendar|
*EDITAR_TQT_DTULTTROCA:IwCalendar|
*EDITAR_GTT_DTULTTROCA:IwCalendar|

It's a default, I need to remove everything that starts with * and has the value IwCalendar and the pipe | at the end of the string, ie remove the sayings whose.

I need to do something generic because there are dozens of fields like this.

Thank you for the force !!! Good morning to all.

    
asked by anonymous 28.09.2015 / 14:30

1 answer

2

Ewerton,

You can do this.

var stringTeste = "EVENTDATE:10/10/2015|*EDITAR_EVENTDATE:IwCalendar|EVENTTIME_INI:12:00|EVENTTIME_END:13:00|RANKINGHC:0|ALERGIAS:0|QUAIS_ALERGIAS:|INFECCAO:0|DATA_INFEC:|SITIO:0|QUADROCLINICO:|ASPECTO:0|*EDITAR_EVENTDATEEND:IwCalendar|";


var expressaoRegular = /\*.*?IwCalendar\|/gm;
var resultado = stringTeste.match(expressaoRegular);
console.log(resultado);

var resultado2 = stringTeste.replace(expressaoRegular, " ");

console.log(resultado2);

Here's an example in jsFiddle

link

    
28.09.2015 / 14:52