regex stop if the next charactere is another

Asked

Viewed 68 times

1

Next: I have this text for example

aluno['ACERTOS_ATV2_D2'] >5.5 & aluno['IDADE'] >24.5 & aluno['PROVA1_D2P'] <0.5 & aluno['ASSISTIU_AULA_1_D2'] <0.5 & aluno['FEZ_FORUM_D2SIM'] > 0.5


I need to do a regex that changes this part in small. for example, this

aluno['PROVA1_D2P'] <0.5** deve ficar **aluno['PROVA1_D2'] != 'P'** (aqui é != pois o simbolo é de menor <) and the aluno['FEZ_FORUM_D2SIM'] > 0.5** deve ficar aluno['FEZ_FORUM_D2'] == 'SIM'** (aque é == pois o simbolo é >)


I’m doing 2 regex, one for each symbol of > <. No problem doing 2x. The first replacement works, but when I go to do the second, it of the problem.

My regex is like this:

/(PROVA1_D2|FEZ_FORUM_D2)(.*?)\]\s\<\d\.\d/g
o replace está $1'] == '$2

aluno['ACERTOS_ATV2_D2'] >5.5 & aluno['IDADE'] >24.5 & aluno['**PROVA1_D2'] != 'P'** & aluno['ASSISTIU_AULA_1_D2'] <0.5 & aluno['FEZ_FORUM_D2SIM'] >0.5


So far ok, all right, but when I do the second part (which is in my case is only reverses in the regex the < by >) the match he makes is this

aluno['ACERTOS_ATV2_D2'] >5.5 & aluno['IDADE'] >24.5 & aluno['**PROVA1_D2'] != 'P' & aluno['ASSISTIU_AULA_1_D2'] <0.5 & aluno['FEZ_FORUM_D2SIM'] >0.5**


It should be this

aluno['ACERTOS_ATV2_D2'] >5.5 & aluno['IDADE'] >24.5 & aluno['PROVA1_D2'] != 'P' & aluno['ASSISTIU_AULA_1_D2'] <0.5 & aluno['**FEZ_FORUM_D2SIM'] >0.5

Remembering that it’s all in a row this text, is that gets kind of big and ends up breaking here

EDIT 1:

I thought it was all right what I had done in my own answer, but I just found a little problem.

((PROVA1_D2|FEZ_FORUM_D2|REGIAO)(\w+))(.*?)\]\s\>\d\.\d

this regex is giving this match (between the asterisks)

aluno['*********REGIAOsudeste'] <0.5 & aluno['ANOCONCL_2G'] >2015.5 & aluno['IDADE'] <42.5 & aluno['ACERTOS_ATV3_D1'] <2.5 & aluno['BOLSA'] >0.2*************5 & aluno['PROVA1_D2P'] <0.5 & aluno['FEZ_FORUM_D2SIM'] <0.5

And in fact I wanted to not give any match, since in regex is the symbol of major (>), not the smallest (<)! The match would only happen with the minor symbol "<"

If need be, I’ve saved the situation here REGEX

1 answer

1


Try to use it like this

((PROVA1_D2|FEZ_FORUM_D2|REGIAO)(\w+))\'\]\s(?!\<)\>\d{1}\.\d{1,2}

And the regex so

$2'] == '$3'

Browser other questions tagged

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