Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
2 つの文字列の最初の文字列のみを選択する正規表現を作成しようとしています。
いいえ:
hello:howareyou
正規表現のみを返すようにしhelloます。
hello
同様に、もう 1 つ、howareyou を返してもらいたいのですが、最初の部分を理解すれば、それを理解できるはずです。
ありがとうございました!
これまでのところ私は試し(?:[^"<:]|"[^"]*"|<[^>]*)* ましたが、それは単に2つを分割するだけです.
(?:[^"<:]|"[^"]*"|<[^>]*)*
単純に を使用することもできますexplode(':', $str)が、どうしても正規表現を使用する場合は、最初の部分をで、2 番目の部分をpreg_match('/(.+?):(.+)/', $str, $matches)で返すこともできます。$matches[1]$matches[2]
explode(':', $str)
preg_match('/(.+?):(.+)/', $str, $matches)
$matches[1]
$matches[2]