regex - finding a character in a pattern in regular expression -
i trying find occurances of equals within quotes in string
if input string is:
anything='', bob2='age=24, sex=m', dilan=24, noble1='yellow'
i wish find characters follows
anything='', bob2='age=24, sex=m', dilan=24, nobel1=24 ^ ^
followed replacing as
anything='', bob2='age~24, sex~m', dilan=24, nobel1=24 ^ ^
i tried following find occurances
'[^',].+?'
but didnt work.
it's quite difficult implement requirement regex.
i'd iterate string char char implement it.
please check code below. have put comment inside it. i'm using java can utilize algorithm inside it.
public class main { public static void main(string args[]){ string input = "param1='', param2='age<b>=</b>24, sex<b>=</b>m', param3=24, param4='yellow'"; char[] arr = input.tochararray(); boolean close = true; /** * iterate char array */ for(int = 0;i < arr.length;i++){ if(arr[i] == '\''){ /** * ignore escaped ' char in '' */ if(i > 0 && arr[i - 1] == '\\'){ break; } /** * use close check whether equal sign inside '' */ if(close){ close = false; }else{ close = true; } }else if(arr[i] == '='){ if(!close){ arr[i] = '~'; } } system.out.print(arr[i]); } } }
Comments
Post a Comment