使用正则表达式C ++进行搜索(Searching using regular expressions C++)

编程入门 行业动态 更新时间:2024-10-22 03:05:31
使用正则表达式C ++进行搜索(Searching using regular expressions C++)

我正在使用Boost.Regex来实现这样的目标:搜索“|” 然后取“|”的左侧部分 并把它放在一个字符串,与右边部分相同:

string s1; string s2; who | sort

在这之后,s1应该是“谁”,而s2应该是“排序”。 如果我记得很好,它在Python中是可行的,我怎么能在Boost中使用正则表达式呢?

谢谢。

I'm using Boost.Regex to achieve something like this: search for a "|" and then take the left part of the "|" and put it a string, same with the right part:

string s1; string s2; who | sort

After this s1 should be "who" and s2 shoudl be "sort". If I remember good, it was posible in Python, how can I do it using regular expressions in Boost ?

Thank you.

最满意答案

#include <boost/algorithm/string.hpp> std::vector<std::string> strs; boost::split(strs, "string to split", boost::is_any_of("|"));

用C ++拆分一个字符串?

#include <boost/algorithm/string.hpp> std::vector<std::string> strs; boost::split(strs, "string to split", boost::is_any_of("|"));

Split a string in C++?

更多推荐

本文发布于:2023-08-07 09:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463747.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正则表达式   Searching   expressions   regular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!