怎么用bat截取指定字符串中间的字符串? java正则截取指定字符串
\u5982\u4f55\u7528\u6279\u5904\u7406\u83b7\u53d6\u6587\u672c\u4e2d\u4e24\u6bb5\u6307\u5b9a\u5b57\u7b26\u4e32\u4e2d\u95f4\u7684\u5185\u5bb9@echo offfor /f "tokens=2 delims=[]" %%i in ('findstr /i counts a.txt^|findstr match') do echo %%i
import java.util.regex.Matcher;import java.util.regex.Pattern; public class Hello { public static void main(String[] args) { String re = "\\[([^\\]]+)\\]"; String str = "[\u60a8\u597d]\uff0cabcdefg\uff0c[abc]"; Pattern p = Pattern.compile(re); Matcher m = p.matcher(str); while(m.find()){ System.out.println(m.group(1)); } }}
1 如果是取最左的特定字符(串)之后的部分可用set "MyVarB=%MyVarA:*.=%"
意思是变量MyVarA第一个.及之前部分替换为空
则MyVarB取得last.stand
当然继续以此方法总是可以取到最后部分
:get
if not "%MyVarB:.=%"=="%MyVarB%" set MyVarB=%MyVarB:*.=%&goto :get
2 对于取最后一个点后的部分,可以把它想象成一个带后缀的文件名
for %%i in ("%MyVarA%") do set "Vq=%%~xi"
set "MyVarB=%Vq:.=%"
注: set 命令后的引号不是必要的%%~xi 表示取后缀名 for命令中的双%%符如在命令行需改为单%
因后缀名是带.的,再把点替换为空(或去掉第一字符set "MyVarB=%Vq:~1%")
3 for命令是循环命令语法比较复杂比如还可以:
for %%i in ("%MyVarA:.=","%") do set "MyVarB=%%~i"
将原串每个.换成"," 且首尾都加上引号,这样形成 "the","last","stand"的字符串
会以逗号为分隔符,循环执行do后的赋值命令,虽然执行了3次但最后一次是最终的赋值情况
还可有其它方法,建议先把如set这样的简单命令熟悉了再去研究for这样的复杂命令
绛旓細1 濡傛灉鏄彇鏈宸︾殑鐗瑰畾瀛楃(涓)涔嬪悗鐨勯儴鍒嗗彲鐢 set "MyVarB=%MyVarA:*.=%"鎰忔濇槸鍙橀噺MyVarA绗竴涓.鍙婁箣鍓嶉儴鍒嗘浛鎹负绌 鍒橫yVarB鍙栧緱last.stand 褰撶劧缁х画浠ユ鏂规硶鎬绘槸鍙互鍙栧埌鏈鍚庨儴鍒 :get if not "%MyVarB:.=%"=="%MyVarB%" set MyVarB=%MyVarB:*.=%&goto :get 2 瀵逛簬鍙栨渶鍚庝竴涓偣...
绛旓細棣栧厛锛瀛楃涓叉埅鍙鏄鎵瑰鐞涓渶甯哥敤鐨勫姛鑳斤紝閫氳繃鎸囧畾浣嶇疆锛屽彲浠ヤ粠瀛楃涓蹭腑鑾峰彇鎴栧垹闄鐗瑰畾瀛楃鎴栧瓧绗﹀簭鍒椼備緥濡傦紝浣跨敤%婧愬瓧绗︿覆:~璧峰鍊,鎴彇闀垮害%鏉ュ疄鐜般傛浛鎹㈠瓧绗︿覆鍒欐秹鍙婂埌鏌ユ壘骞舵浛鎹㈢壒瀹氱殑瀛楃鎴栧瓙涓诧紝渚嬪锛屽皢%aa:涓浗=涓崕浜烘皯鍏卞拰鍥%杩欐牱鐨勮〃杈惧紡璧嬪肩粰鍙橀噺aa锛屽嵆鍙疄鐜版浛鎹傚悎骞跺瓧绗︿覆鍒欐槸绠鍗曠殑杩...
绛旓細棣栧厛锛屾垜浠缃彉閲忋備娇鐢╜set`鍛戒护锛屽彲浠ヤ负鍙橀噺璧嬪硷紝濡俙set Sender=%1`鎺ユ敹绗竴涓弬鏁颁綔涓哄彂閫佽銆傛嫾鎺ュ瓧绗︿覆鍙互閫氳繃`set`鍛戒护鍜宍&`鎿嶄綔绗︼紝渚嬪`set Receiver=%2, %3`灏嗙浜屼釜鍜岀涓変釜鍙傛暟杩炴帴璧锋潵锛屼腑闂寸敤閫楀彿鍒嗛殧銆傛埅鍙栦俊鎭唴瀹瑰彲鑳介渶瑕佸熷姪涓浜涘瓧绗︿覆鍑芥暟銆傚亣璁綻%4`宸茬粡瀛樺偍浜嗗畬鏁寸殑娑堟伅锛...
绛旓細::瑙i噴锛氬厛鐢ㄥ彉閲鎴彇锛屽垹闄も/"鍙婂墠闈㈢殑鎵鏈夊瓧绗︼紝寰楀埌瀛楃涓鈥渁jsnfjakfb@sgsr鈥濓紝鍐嶇敤for鍛戒护锛屼互鈥淍鈥濅负鍒嗛殧绗︼紝灏嗗瓧绗︿覆鍒嗘垚涓ら儴鍒嗏渁jsnfjakfb鈥濅笌鈥渟gsr鈥濓紝鏈鍚庡彇鍏剁涓閮ㄥ垎鍗冲彲
绛旓細绗9琛岃缃枃浠惰矾寰,杈撳嚭缁撴灉涓 "鍘熸枃浠跺悕.log".<# :@echo off&cd/d "%~dp0"more +8 "%~f0" >"%temp%\%~n0.ps1"powershell -NoLogo -NoProfile -ExecutionPolicy bypass -File "%temp%\%~n0.ps1"del /f /q "%temp%\%~n0.ps1"pause#>$file='a.txt';#鏂囦欢璺緞$content=...
绛旓細鍋囪鍘熸枃浠跺悕涓1.txt (for /f "tokens=2 delims=:@ " %i in ('findstr "component:" 1.txt') do @echo %i)>a.txt
绛旓細echo offrem 鏍规嵁浠庢枃浠跺悕涓鎸囧畾瀛楃涓/鍏抽敭璇嶅紑濮鎴彇鎸囧畾浣嶆暟鐨勫瓧绗︽潵绉诲姩鏂囦欢鍒板搴旀枃浠跺すset #=q&set/azx=0x53b7e0b4title Any question +%#%%#% %zx%cd /d "%~dp0"set "keyword=20191231"set "n=15"powershell -NoProfile -ExecutionPolicy bypass ^ $files=@(dir^|?{($_ -is...
绛旓細set fso=createobject("scripting.filesystemobject")set file=fso.opentextfile("ini.txt",1) 'ini.txt鏀逛负浣犺璇诲彇鐨勬枃浠剁殑缁濆璺緞 do while file.atendofstream<>true opt=file.readline ip=ip&split(split(opt,"=")(1),".")(0)&"."&split(split(opt,"=")(1),".")(1)&vbcrlf loop...
绛旓細echo offsetlocal enabledelayedexpansionif exist 456.txt del 456.txtfor /f "tokens=1,2 delims== " %%i in (123.txt) do (if /i "%%i"=="s" set str=%%jif /i "%%i"=="y" set str1=%%jif /i "%%i"=="z" echo %%j00 !str1!00 !str!>>456.txt)pause ...
绛旓細echo offset "str=C:\Program Files (x86)\360Apps\Green\10101010\abc"for /f "delims=" %%i in ("%str%") do (echo %%~dpi)pause鍙橀噺涓轰竴涓畬鏁磋矾寰勭敤for 鍛戒护寰堝鏄撳鐞.