+ Start a Discussion
LALALALALALA 

Regex Issue

Is anyone can help me that will be so appreciate:)

My question is: when i use 'If' my regex can grab data of city and postal code,,,,but if I use 'while' to loop those data, I can't grab any data of city and postal code, I don;t know why.......But I have to use 'while'  because in datatable have two different city and postal code,  so I need Loop,,,,please any one help me:)

this is my example code:
Pattern p9 = Pattern.compile('City\\s*(?:<[^>]+>){1,}\\s*:([^<]+)');
            Matcher m9 = p9.matcher(myHtmlText);
            string dt1;
            string City;
            string Pcode;
            string [] str;
            while(m9.find()) {
                system.debug(m9.group(1));
                dt1 = m9.group(1).replaceAll('(<[^>]*>|&nbsp;)','');
                str = dt1.split('\\,');
            }         
            //City
            city = str[0];
            
            //Postal Code
            Pcode = str[1];
pconpcon
Can you please provide an example of your myHtmlText so that I can run your code?  Also, are you trying to get multiple cities / postal codes out of the html?  Is that where the problem is?