Remove white space using Regular Expressions

本文介绍了一系列实用的字符串处理方法,包括去除两端空白字符、特定前缀和后缀、使用正则表达式进行匹配与替换等。这些技巧对于前端开发中常见问题的解决非常有用。

1. Remove white space from both ends of a string.

     string = string.replace(new RegExp(/^/s+/),""); // START

    string = string.replace(new RegExp(//s+$/),""); // END

2. Remove white space from ends then 'http://' from the start.

     string = string.replace(new RegExp(/^http://///i),"");

3. Remove white space from ends then 'www.' from the start.

     string = string.replace(new RegExp(/^www/./i),"");

4. Remove white space from ends then any trailing forward slash.

     string = string.replace(new RegExp(///$/),"");

5. Remove white space from ends then split the string at first forward slash.

     string = string.split(new RegExp(////),1);

6. Remove white space from ends then replace back slashes with forward slashes.

     string = string.replace(new RegExp(////g),"/");

7. Test for a match at end of string against a number of different options.

     if (domainName.match(//.com$|/.net$|/.us$|/.co/.uk$/i))

     {
         return(true);
     }

     else

     {
        return(false);
     }

Note: In the context of this demonstration the term 'white space' includes any non-printing character, that is any character you cannot see. Examples include blank spaces, carriage returns, line feeds, tab characters, etc.

 

RegExp: A regular expression object contains the pattern of a regular expression. It has properties and methods for using that regular expression to find and replace matches in strings or to match patterns in strings. JavaScript RegExp can be used in the following JavaScript String Methods: string.match(), string.search(), string.replace() and string.split().

    

[71]"D:/Work/CCS/ccs_20/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mlittle-endian -mthumb -gdwarf-3 -march=armv7e-m -Wl,-m"simple_tx_rfprop.map" -Wl,-i"D:/Work/SatIoT/CC1352/SDK/simplelink_cc13xx_cc26xx_sdk_8_30_01_01/source" -Wl,-i"D:/Work/SatIoT/CC1352/SDK/simplelink_cc13xx_cc26xx_sdk_8_30_01_01/kernel/tirtos7/packages" -Wl,-i"D:/Work/Project/jiang/bload-master/simple_tx_rfprop/Debug/syscfg" -Wl,-i"D:/Work/CCS/ccs_20/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/lib" -Wl,--diag_wrap=off -Wl,--display_error_number -Wl,--warn_sections -Wl,--xml_link_info="simple_tx_rfprop_linkInfo.xml" -Wl,--rom_model -o "simple_tx_rfprop.out" "./main_tirtos.o" "./rfPacketTx.o" "./syscfg/ti_devices_config.o" "./syscfg/ti_radio_config.o" "./syscfg/ti_drivers_config.o" "./syscfg/ti_sysbios_config.o" "./oad/bim_interface.o" "./oad/flash_interface.o" "./oad/oad_image_header.o" "./oad/upgrade_manager.o" "../cc13x2_cc26x2_tirtos7_active.cmd" -Wl,-lti_utils_build_linker.cmd.genlibs -Wl,-llibc.a [72]gmake[1]: *** No rule to make target 'input-file.error', needed by 'output-file.error'. [73]Finished building target: "simple_tx_rfprop.out" [74]D:/Work/CCS/ccs_20/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmobjcopy -O ihex simple_tx_rfprop.out simple_tx_rfprop.hexD:/Work/SatIoT/CC1352/SDK/simplelink_cc13xx_cc26xx_sdk_8_30_01_01/tools/common/oad/oad_image_tool --verbose ccs D:/Work/Project/jiang/bload-master/simple_tx_rfprop/Debug 7 -hex1 D:/Work/Project/jiang/bload-master/simple_tx_rfprop/Debug/simple_tx_rfprop.hex -k D:/Work/SatIoT/CC1352/SDK/simplelink_cc13xx_cc26xx_sdk_8_30_01_01/tools/common/oad/private.pem -o D:/Work/Project/jiang/bload-master/simple_tx_rfprop/Debug/simple_tx_rfprop_oad [75]OVERVIEW: llvm-objcopy tool [76]USAGE: llvm-objcopy [options] input [output] [77]OPTIONS: [78] --add-gnu-debuglink=debug-file [79] Add a .gnu_debuglink for <debug-file> [80] --add-note-segment=file Make a note segment with the contents of <file>. [81] --add-section=section=file [82] Make a section named <section> with the contents of <file> [83] --add-symbol=name=[section:]value[,flags] [84] Add new symbol <name> to .symtab. Accepted flags: global, local, weak, default, hidden, protected, file, section, object, function, indirect-function. Accepted but ignored for compatibility: debug, constructor, warning, indirect, synthetic, unique-object, before [85] --adjust-start <value> Alias for --change-start [86] --allow-broken-links Allow the tool to remove sections even if it would leave invalid section references. The appropriate sh_link fields will be set to zero. [87] --binary-architecture=<value> [88] Ignored for compatibility [89] -B <value> Alias for --binary-architecture [90] --change-start=incr Add <incr> to the start address. Can be specified multiple times, all values will be applied cumulatively [91] --compress-debug-sections=format [92] Compress DWARF debug sections using specified format. Supported formats: zlib, zstd. Select zlib if <format> is omitted [93] --core-exe=coreid:filename [94] Specify an ELF executable for a Core ID as input. [95] --decompress-debug-sections [96] Decompress DWARF debug sections [97] --disable-deterministic-archives [98] Disable deterministic mode when operating on archives (use real values for UIDs, GIDs, and timestamps). [99] --discard-all Remove all local symbols except file and section symbols. Also remove all debug sections [100] --discard-locals Remove compiler-generated local symbols, (e.g. symbols starting with .L) [101] --dump-mmELFConfig Dump the contents of the internal mmELFConfig structure. [102] --dump-section=section=file [103] Dump contents of section named <section> into file <file> [104] -D Alias for --enable-deterministic-archives [105] --enable-deterministic-archives [106] Enable deterministic mode when operating on archives (use zero for UIDs, GIDs, and timestamps). [107] --extract-dwo Remove all sections that are not DWARF .dwo sections from file [108] --extract-main-partition [109] Extract main partition from the input file [110] --extract-partition=name [111] Extract named partition from input file [112] -F <value> Alias for --target [113] --gap-fill=value Fill the gaps between sections with <value> instead of zero. <value> must be an unsigned 8-bit integer. This option is only supported for ELF input and binary output [114] --globalize-symbol=symbol [115] Mark <symbol> as global [116] --globalize-symbols=filename [117] Reads a list of symbols from <filename> and marks them global [118] -G <value> Alias for --keep-global-symbol [119] -g Alias for --strip-debug [120] --input-target=<value> Format of the input file [121] -I <value> Alias for --input-target [122] -j <value> Alias for --only-section [123] --keep-file-symbols Do not remove file symbols [124] --keep-global-symbol=symbol [125] Convert all symbols except <symbol> to local. May be repeated to convert all except a set of symbols to local [126] --keep-global-symbols=filename [127] Reads a list of symbols from <filename> and runs as if --keep-global-symbol=<symbol> is set for each one. <filename> contains one symbol per line and may contain comments beginning with '#'. Leading and trailing whitespace is stripped from each line. May be repeated to read symbols from many files [128] --keep-section=section Keep <section> [129] --keep-symbol=symbol Do not remove symbol <symbol> [130] --keep-symbols=filename Reads a list of symbols from <filename> and runs as if --keep-symbol=<symbol> is set for each one. <filename> contains one symbol per line and may contain comments beginning with '#'. Leading and trailing whitespace is stripped from each line. May be repeated to read symbols from many files [131] --keep-undefined Do not remove undefined symbols [132] -K <value> Alias for --keep-symbol [133] --localize-hidden Mark all symbols that have hidden or internal visibility as local [134] --localize-symbol=symbol [135] Mark <symbol> as local [136] --localize-symbols=filename [137] Reads a list of symbols from <filename> and marks them local [138] -L <value> Alias for --localize-symbol [139] --new-symbol-visibility=<value> [140] Visibility of symbols generated for binary input or added with --add-symbol unless otherwise specified. The default value is 'default' [141] -N <value> Alias for --strip-symbol [142] --only-keep-debug Produce a debug file as the output that only preserves contents of sections useful for debugging purposes [143] --only-section=section Remove all but <section> [144] --output-target=<value> Format of the output file [145] -O <value> Alias for --output-target [146] --pad-to=address Pad the output up to the load address <address>, using a value of zero or the value specified by the --gap-fill option. This option is only supported for ELF input and binary output [147] --prefix-alloc-sections=prefix [148] Add <prefix> to the start of every allocated section name [149] --prefix-symbols=prefix Add <prefix> to the start of every symbol name [150] --preserve-dates Preserve access and modification timestamps [151] -p Alias for --preserve-dates [152] --redefine-sym=old=new Change the name of a symbol old to new [153] --redefine-syms=filename [154] Reads a list of symbol pairs from <filename> and runs as if --redefine-sym=<old>=<new> is set for each one. <filename> contains two symbols per line separated with whitespace and may contain comments beginning with '#'. Leading and trailing whitespace is stripped from each line. May be repeated to read symbols from many files [155] --regex Permit regular expressions in name comparison [156] --remove-section=section [157] Remove <section> [158] --rename-section=old=new[,flag1,...] [159] Renames a section from old to new, optionally with specified flags. Flags supported for GNU compatibility: alloc, load, noload, readonly, exclude, debug, code, data, rom, share, contents, merge, strings, large [160] -R <value> Alias for --remove-section [161] --set-section-alignment=section=align [162] Set alignment for a given section [163] --set-section-flags=section=flag1[,flag2,...] [164] Set section flags for a given section. Flags supported for GNU compatibility: alloc, load, noload, readonly, exclude, debug, code, data, rom, share, contents, merge, strings, large [165] --set-section-type=section=type [166] Set the type of section <section> to the integer <type> [167] --set-start=addr Set the start address to <addr>. Overrides any previous --change-start or --adjust-start values [168] --shared-obj=filename Specify a static shared object file as input for building an mmELF file. [169] --split-dwo=dwo-file Equivalent to extract-dwo on the input file to <dwo-file>, then strip-dwo on the input file [170] --strip-all-gnu Compatible with GNU's --strip-all [171] --strip-all Remove non-allocated sections outside segments. .gnu.warning* and .ARM.attribute sections are not removed [172] --strip-debug Remove all debug sections [173] --strip-dwo Remove all DWARF .dwo sections from file [174] --strip-non-alloc Remove all non-allocated sections outside segments [175] --strip-sections Remove all section headers and all sections not in segments [176] --strip-symbol=symbol Strip <symbol> [177] --strip-symbols=filename [178] Reads a list of symbols from <filename> and removes them [179] --strip-unneeded-symbol=symbol [180] Remove symbol <symbol> if it is not needed by relocations [181] --strip-unneeded-symbols=filename [182] Reads a list of symbols from <filename> and removes them if they are not needed by relocations [183] --strip-unneeded Remove all symbols not needed by relocations [184] --subsystem=name[:version] [185] Set PE subsystem and version [186] -S Alias for --strip-all [187] --target=<value> Format of the input and output file [188] --update-section=name=file [189] Replace the contents of section <name> with contents from a file <file> [190] -U Alias for --disable-deterministic-archives [191] --version Print the version and exit. [192] -V Alias for --version [193] --weaken-symbol=symbol Mark <symbol> as weak [194] --weaken-symbols=filename [195] Reads a list of symbols from <filename> and marks them weak [196] --weaken Mark all global symbols as weak [197] --wildcard Allow wildcard syntax for symbol-related flags. Incompatible with --regex. Allows using '*' to match any number of characters, '?' to match any single character, '' to escape special characters, and '[]' to define character classes. Wildcards beginning with '!' will prevent a match, for example "-N '*' -N '!x'" will strip all symbols except for "x". [198] -W <value> Alias for --weaken-symbol [199] -w Alias for --wildcard [200] -X Alias for --discard-locals [201] -x Alias for --discard-all [202]Pass @FILE as argument to read options from FILE. [203]gmake[1]: Target 'secondary-outputs' not remade because of errors. [204]gmake: *** [makefile:155: all] Error 2 报错
最新发布
07-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值