mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-08 21:23:48 -05:00
_cleanstring_: allow regex
This commit is contained in:
@@ -131,6 +131,12 @@ _testCleanString_() {
|
|||||||
assert_output "this is a-string"
|
assert_output "this is a-string"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "_cleanString_: alnum w/ spaces and dashes and regex replace" {
|
||||||
|
run _cleanString_ -asp "-|_|st, " "th_is(is)a-string"
|
||||||
|
assert_success
|
||||||
|
assert_output "th is is a ring"
|
||||||
|
}
|
||||||
|
|
||||||
@test "_cleanString_: user replacement" {
|
@test "_cleanString_: user replacement" {
|
||||||
run _cleanString_ -p "e,g" "there should be a lot of e's in this sentence"
|
run _cleanString_ -p "e,g" "there should be a lot of e's in this sentence"
|
||||||
assert_success
|
assert_success
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ _cleanString_() {
|
|||||||
# -s In combination with -a, replaces characters with a space
|
# -s In combination with -a, replaces characters with a space
|
||||||
# OUTS: Prints result to STDOUT
|
# OUTS: Prints result to STDOUT
|
||||||
# USAGE: _cleanString_ [OPT] [STRING] [CHARS TO REMOVE]
|
# USAGE: _cleanString_ [OPT] [STRING] [CHARS TO REMOVE]
|
||||||
# _cleanString_ -p " ,-" [STRING] [CHARS TO REMOVE]
|
# _cleanString_ -lp " ,-" [STRING] [CHARS TO REMOVE]
|
||||||
# NOTES: Always cleaned:
|
# NOTES: Always cleaned:
|
||||||
# - leading white space
|
# - leading white space
|
||||||
# - trailing white space
|
# - trailing white space
|
||||||
@@ -80,7 +80,7 @@ _cleanString_() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if "${replace}"; then
|
if "${replace}"; then
|
||||||
string="$(echo "${string}" | sed "s/${pairs[0]}/${pairs[1]}/g")"
|
string="$(echo "${string}" | sed -E "s/${pairs[0]}/${pairs[1]}/g")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# trim trailing/leading white space and duplicate dashes
|
# trim trailing/leading white space and duplicate dashes
|
||||||
|
|||||||
Reference in New Issue
Block a user