Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. QRegularExpression: Wie prüfen of "/P" zweimal vorkommt?
Forum Updated to NodeBB v4.3 + New Features

QRegularExpression: Wie prüfen of "/P" zweimal vorkommt?

Scheduled Pinned Locked Moved Solved German
3 Posts 2 Posters 390 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    Urbi
    wrote on last edited by Urbi
    #1

    Hallo,
    Ich möchte in einem String mit Hilfe von QRegularExpression prüfen ob "/P" zweimal vorkommt. /P kommt dabei immer nor am Ende eines Wortes vor. "abcfrt/P tghet/P 4678 uz" soll positiv sein (weil zweimal "/P" enthalten), "abcfrtP tghet/P 4678 uz" abr negativ ("/P" nur einmal enthalten). Wie kann ich das realisieren?
    Was muss ich bei QRegularExpression in den Klammen als Kriterium eingeben?
    Habe "\w+/P \w+/P" probiert, aber es funktioniert nicht, weil es auch schon bei einmal /P positiv wird.

    jsulmJ 1 Reply Last reply
    0
    • U Urbi

      Hallo,
      Ich möchte in einem String mit Hilfe von QRegularExpression prüfen ob "/P" zweimal vorkommt. /P kommt dabei immer nor am Ende eines Wortes vor. "abcfrt/P tghet/P 4678 uz" soll positiv sein (weil zweimal "/P" enthalten), "abcfrtP tghet/P 4678 uz" abr negativ ("/P" nur einmal enthalten). Wie kann ich das realisieren?
      Was muss ich bei QRegularExpression in den Klammen als Kriterium eingeben?
      Habe "\w+/P \w+/P" probiert, aber es funktioniert nicht, weil es auch schon bei einmal /P positiv wird.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Urbi Du kannst match() benutzen und dann prüfen was https://doc.qt.io/qt-5/qregularexpressionmatch.html#lastCapturedIndex zurück gibt.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • U Offline
        U Offline
        Urbi
        wrote on last edited by
        #3

        Nach langem Probieren habe ich jetzt herausgefunden, dass folgendes funktioniert: "(\w+)/P (\w+)/P"

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved