Catch string first with regex

Asked

Viewed 124 times

0

I need to do 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 pattern, I need to remove everything that starts with * and has the value IwCalendar and the pipe | at the end of the string, i.e., remove the sayings whose.

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

Already thank you for the strength!!! Good morning to all.

1 answer

2


Ewerton,

You can do it like 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

http://jsfiddle.net/1b7s1yv8/1/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.