Regular expression describes a pattern of matching string Can be used to detect/replace/take out specific substring
Syntax
symbol
description
example
^
match the beginning of he line
[ABC]
match all char in […]
[aeiou]: google runoob taobao
[^ABC]
match all except those in […]
[A-Z]
describe an interval
[a-z] matchs all lower case char
(…)
set groups
\1…\n
match the same elements as nth group
{n}
the front element repeats n times
{n,}
the front element repeats at least n times
{n,m}
the front element repeats at least n and at most m times
.
match any char except (\n,\r), same with [^\n\r]
\s\S
match all, \s:match all space char, \S:match all non space char, ‘return’ not included
\w
match letter,number,underline, equal to [A-Za-z0-9 ]
\cx
match the control char indicated by x(A-Z/a-z)
\cM: Control-M or return char
\f
match a page change char
\n\r
match a return symbol
\t
match a tab
\v
match a vertical tab
$
match the end of the string, to match $ itself, use $
*
match the front subexpression multiple or zero times, use \* to match *
+
match the front subexpression multiple or one times, use \+
.
match any single char except \n
[
mark the beginning of a []expression
?
match the front subexpression one or zero times, or indicate a non-greedy qualifier
|
logic or
Application in Cpp
In cpp, we use std::regex to express regular expression, supporting ECMAScripts as default.
Match
Use regex_match() to match xml (or html) format:
1 2 3 4 5 6 7 8 9 10 11
std::regex reg("<.*>.*</.*>");
bool ret = std::regex_match("<xml>value</xml>",reg); assert(ret);
bool ret = std::regex_match("<html>value</html>",reg); assert(ret);
bool ret = std::regex_match("<xml>value<xml>",reg); assert(ret);
Search
Use std::regex_search. As long as there exists targets in the string, it will return.
1 2 3 4 5 6 7 8
std::regex reg("<(.*)>(.*)</(\\1)>"); std::cmatch m; auto ret = std::regex_search("123<xml>value</xml>456", m, reg); if (ret){ for (auto& elem : m) std::cout<<elem<<std::endl; }
Posted Updated Notea few seconds read (About 106 words)
Study note for ROS * Core Concept ** Node and ROS Master *** Node implement functions for purposes support various language can have thousands of nodes *** ROS Master mange the registion and name of various nodes support(trace and record) communication between different nodes for nodes to find each other provide parameter server(store global variables...)[[about parameter]] ** Communication between nodes | | Topic | Service | |--------------------+---------------------+----------------| | sync | n | y | | model | publish/subscribe | service/client | | protocol | ROSTCP/ROSUDP | ROSTCP/ROSUDP | | response | n | y | | buffer | y | n | | real-time | weak | strong | | nodes relationship | multi/one to multi | one to multi | | scene | data transformation | logic process | *** Topic Node(publisher)->Topic(/example)&Message_Tyoe(std_msgs/String)->other ROS nodes(subscriber) Message: define the data type and struct of data, defined by .msg file async *** Service C/S model(Client/Server) client send requests, server return response data defined by .srv file, defines the structure of the requests and response ROS node(Service Server) ^ |response request| v ROS node(Service Client) sync ** Parameter <<about parameter>> talker -> ROS master : setParam("foo",1) listener -> ROS master: getParam("foo") ROS master ->listener: {"foo",1}
multiple variable dictionary for storing static nonbinary configuration, not suitable for dynamic ** File system *** package Basic unit in ROS, include the src of nodes, cfg, data def *** package manifest record the basic information of packages *** Meta packages orgnize multi packages for one common purpose * Commond Line Tools ** rqt_graph visualize tool display the calculate process graph ** rosnode display node information *** rosnode list list all node default node /rosout *** rosnode info /turtle_sim show info of a node ** rostopic usage like rosnode(list,info) *** rostopic pub /../.. data_structure data publish message as a topic add -r num to repeat sending at rate num/s ** rosmsg *** rosmsg show data_structure show the data structure ** rosservice | commond addition | | |------------------------+-----------------------------------| | list | list all service the node provide | | call service_name data | | ** rosbag | command addition | | | | |-------------------------+-----------------------------------------------+--------+-----------------| | record -a -O cmd_record | record the topic data in the system | -a:all | -O as a package | | play cmd_record.bag | play the recorded data of previous simulation | | | | | | | | * setup workspace and function package ** workspace *** overview | src | source space | | | build | build space | no need to touch | | devel | develop space | script, executable file | | install | install sapce | |
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.