0

Let's say I have a text file with these contents:

color1 = yellow.$199 * 100
         color2 =         red.$1 * 22
         myNextColor =  green.$3
         whatsNext = blue.$$
         oneMore =     orange.$

I need to be able to get an array like this:

colorsInFile = ["yellow","red","green","blue","orange"]

In python, the regex for picking this out is:

r'=\s*(\w+)\s*\.\$'

What's the java equivalent?
Thanks for the help :)

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by AhmedGhazey
0

i hope this help you , and the same for the others

public static void main(String[] args) {
      //  System.out.println("aaaa");
        
        String source = "color1 = yellow.$199 * 100";

        Pattern p = Pattern.compile("([a-zA-Z]+\\d+?) = (([a-zA-Z]+)(.)*) ");

        Matcher m = p.matcher(source);

        while (m.find()) {
            // will return yellow 
            System.out.println(m.group(3));
           
        }
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.