#' Remove Brackets and Double \\s from R type Regular Expression
#'
#' @param pattern R type regular expression
#' @param expr A string vector containing expressions, \cr
#'  or a string which contains several expressions separated by a comma, \cr
#'  or "".
#'
#' @details
#'  A pattern w/o brackets will be printed which can be pasted to \cr
#'  \code{https://jex.im/regulex/#!flags=&re=\%5E(a\%7Cb)*\%3F\%24}.
#'
#' @return
#'  NONE
#'
#' @examples
#' testregex( "^[[:alpha:].][[:alnum:]_.]*$" )
#' testregex( "^[[:alpha:].][[:alnum:]_.]*$"
#'         , c( "a1", "b", ".c1.", "@d_", "1_2", "._" ) )
#' testregex( "^((([[:alpha:]]|[.][._[:alpha:]])[._[:alnum:]]*)|[.])$"
#'         , "a1, b, .c1., @d_, 1_2, ._" )
#'
#'
#' @export
#'

testregex <- function( pattern, expr="" ){
  # testing regular expression
  # Shin-ichi Mayekawa
  # 20200616dnc,17
  # 20230430cot
  # Old testregexpr (trx) in lazy.symbolic renamed: 20230509dnc
  # \ added before % in url: 20250305
  #
  # args:
  #  pattern regular expression in R format
  #  expr expressions to be evaluated separated by commas and blanks
  #
  # values
  #  none
  #
  # details
  #  regular expression without [[ and \\ will be printed as pat1
  #  which can be pasted to
  #  \code{https://jex.im/regulex/#!flags=&re=%5E(a%7Cb)*%3F%24}.
  #

 # remove [ and ]
 pat1=gsub("\\\\", "\\", pattern, fixed=1)
 pat1=gsub("[:", ":", pat1, fixed=1)
 pat1=gsub(":]", ":", pat1, fixed=1)
 Print(pat1)

 if( all(expr == "") ) return( invisible() )

 # split expr by comman or blank
 if( length(expr) == 1 ){
  expr=unlist(strsplit(expr,"[ ,]"))
  expr=expr[expr!=""]
 }

 res=regexpr(pattern, expr)

 cat("\npattern\n")
 cat(pattern, "\n")
 cat("\n Result of regexpr: expr starts from column 6.\n")
 resf=formatC(res,width=4,format="d")
 res1=paste(resf, expr, sep=" ")
 cat(res1, sep="\n")

} # end of testregex


