QT正規表示式擷取字串末尾數字

2021-10-07 22:35:15 字數 398 閱讀 3382

qregexp rx("\\d+$");

rx.indexin(old_name, 0);

qstring end_num = rx.cap(0);

說明

1、int qregexp::indexin(const qstring &str, int offset = 0, qregexp::caretmode caretmode = caretatzero) const

從字串str的位置offset開始匹配,返回匹配到的字串在str中的位置

2、qstring qregexp::cap(int nth = 0) const

返回第nth個子表示式捕獲的文字,nth=0表示整個表示式的匹配,圓括號子表示式的索引從1開始(不包括非捕獲括號)。

用正規表示式擷取字串

region 匹配字元 獲取資訊 匹配字元 獲取資訊 被匹配字串 匹配內容 匹配到的資訊 public static string matchfunction string nowhtml text,string matchname catch return values endregion 使用例...

正規表示式擷取字串操作

string str shdfj3h434343hjhjhgfg 第一步,去除空格trim str.trim 定義乙個空的字串 string str1 null if str null equals str system.out.println str1 前面會生成乙個null這個方法只能吧數字提取...

如何用正規表示式擷取字串

有這麼一段字串 數字 字串 結果取 a 數字 b 字串 擷取方法1 int a convert.toint32 txt1.text.trim replace split 1 string b txt1.text.trim replace split 2 擷取方法2 string str 數字 字串 ...