I have an issue and i want your help!I have a specific REGEX which i have named it "unique" and i want to store the data that it gives me!! The prefix and the suffix of this regex!!so!!someone has told me to use
var prefix and
var suffix
but i don't know how to do it!
for your convinience i give u my xml for this regex
<reg name="unique">
<start><![CDATA[ <!-- 72 HOURS FORECASTS -->
]]></start>
<end><![CDATA[<!-- 72 HOURS FORECASTS -->]]></end>
</reg>
the code where i call this regex is
int k = 0;
for(Xml reg_is:fetchsite.child("site").child("regexps").children("reg")) {
    if(reg_is.string("name").contains("unique")){
        if(reg_开发者_开发百科is.child("start").content()=="")
            error += "\tNo prefix reg.exp. given.\n";
        else
              prefix = HtmlMethods.removeBreaks(replaceVariables(reg_is.child("start").content()));                     
        if(reg_is.child("end").content()=="")
            error += "\tNo suffix reg.exp. given.\n";
        else
                suffix = HtmlMethods.removeBreaks(replaceVariables(reg_is.child("end").content()));
    }
    else{
          poleis[k][0]= HtmlMethods.removeBreaks(reg_is.string("name"));
          poleis[k][1] = HtmlMethods.removeBreaks(replaceVariables(reg_is.child("start").content())); 
          poleis[k][2] = HtmlMethods.removeBreaks(replaceVariables(reg_is.child("end").content()));
           k++;
 }
Some general comments on your code:
- Using == to check for - Stringequality is wrong! Use the- equals()method instead:- reg_is.child("end").content().equals("")
- Also, if you're comparing a - Stringvariable to a hard-coded- String, it's better to put the hard-coded String first. That way, if the variable is null, your program won't throw a- NullPointerException(because the hard coded- Stringcan never be null!)- "".equals(reg_is.child("end").content())
- When doing a lot of - Stringconcatenation, it's more efficient to use a- StringBuilder:- StringBuilder error = new StringBuilder(); error.append("\tNo prefix reg.exp. given.\n");
- Like Oscar Reyes said, the safe thing to do with if statements is always use braces. If you add a line and forget to add the braces, you can waste hours tracking down bugs. I know it's happened to me before... - if(reg_is.child("start").content()==""){ error += "\tNo prefix reg.exp. given.\n"; } else { prefix = HtmlMethods.removeBreaks(replaceVariables(reg_is.child("start").content())); }
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论