Котлин, соответствующий шаблону в строке слов [duplicate]

Вы можете избежать рекурсивных вызовов в стек, используя фактическую структуру данных стека довольно просто.

alist = [1,[1,2],[1,2,[4,5,6],3, "33"]]
newlist = []

while len(alist) > 0 :
  templist = alist.pop()
  if type(templist) == type(list()) :
    while len(templist) > 0 :
      temp = templist.pop()
      if type(temp) == type(list()) :
        for x in temp :
          templist.append(x)
      else :
        newlist.append(temp)
  else :
    newlist.append(templist)
print(list(reversed(newlist)))
3
задан pb2q 25 September 2012 в 21:30
поделиться

3 ответа

.*\bEU\b.*

 public static void main(String[] args) {
       String regex = ".*\\bEU\\b.*";
       String text = "EU is an acronym for  EUROPE";
       //String text = "EULA should not match";


       if(text.matches(regex)) {
           System.out.println("It matches");
       } else {
           System.out.println("Doesn't match");
       }

    }
7
ответ дан gtgaxiola 26 August 2018 в 20:58
поделиться

Используйте шаблон с границами слов :

String str = "I am in the EU.";

if (str.matches(".*\\bEU\\b.*"))
    doSomething();

Взгляните на документы для Pattern .

3
ответ дан pb2q 26 August 2018 в 20:58
поделиться

Вы можете сделать что-то вроде

String str = "I am in the EU.";
Matcher matcher = Pattern.compile("\\bEU\\b").matcher(str);
if (matcher.find()) {
   System.out.println("Found word EU");
}
2
ответ дан Reimeus 26 August 2018 в 20:58
поделиться
Другие вопросы по тегам:

Похожие вопросы: