Skip to main content
Corrected output
Source Link
phils
  • 53.1k
  • 3
  • 84
  • 127
(require 's)  ;; All we need is `s-matches-p'
(require 'rx)

Your example:

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil_finder")
;; t

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil")
;; t

Fixed:

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil_finder")
;; nil

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil")
;; t

Better way:

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil_finder")
;; nnil

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil")
;; nt
(require 's)  ;; All we need is `s-matches-p'
(require 'rx)

Your example:

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil_finder")
;; t

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil")
;; t

Fixed:

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil_finder")
;; nil

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil")
;; t

Better way:

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil_finder")
;; n

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil")
;; n
(require 's)  ;; All we need is `s-matches-p'
(require 'rx)

Your example:

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil_finder")
;; t

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil")
;; t

Fixed:

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil_finder")
;; nil

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil")
;; t

Better way:

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil_finder")
;; nil

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil")
;; t
Formatting
Source Link
phils
  • 53.1k
  • 3
  • 84
  • 127
(require 's)  ;; All we need is `s-matches-p'
(require 'rx)
 
;; Your example -----------------------------------------------------------

Your example:

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil_finder")
;; t

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil")
;; t

;; Fixed ------------------------------------------------------------------

Fixed:

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil_finder")
;; nil

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil")
;; t

;; Better way --------------------------------------------------------------

Better way:

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil_finder")
;; n

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil")
;; n
(require 's)  ;; All we need is `s-matches-p'
(require 'rx)
 
;; Your example -----------------------------------------------------------

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil_finder")
;; t

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil")
;; t

;; Fixed ------------------------------------------------------------------

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil_finder")
;; nil

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil")
;; t

;; Better way --------------------------------------------------------------

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil_finder")
;; n

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil")
;; n
(require 's)  ;; All we need is `s-matches-p'
(require 'rx)

Your example:

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil_finder")
;; t

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil")
;; t

Fixed:

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil_finder")
;; nil

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil")
;; t

Better way:

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil_finder")
;; n

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil")
;; n
Added "Better way", reformat code
Source Link
serghei
  • 282
  • 4
  • 15
(require 's)  ;; All we need is `s-matches-p'
(require 'rx)

;; Your example -----------------------------------------------------------

(s-matches-p
  (concat
  "\\<"
  (regexp-opt '("nil" "t") t)
  "\\>")
  "nil_finder")
 
;; t

(s-matches-p
  (concat
  "\\<"
  (regexp-opt '("nil" "t") t)
  "\\>")
  "nil")
 
;; t

;; Fixed ------------------------------------------------------------------

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil_finder")
 
;; nil

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil")
 
;; t

;; Better way --------------------------------------------------------------

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil_finder")
;; n

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil")
;; n
(require 's)  ;; All we need is `s-matches-p'
(require 'rx)

(s-matches-p
  (concat
  "\\<"
  (regexp-opt '("nil" "t") t)
  "\\>")
  "nil_finder")
 
;; t

(s-matches-p
  (concat
  "\\<"
  (regexp-opt '("nil" "t") t)
  "\\>")
  "nil")
 
;; t

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil_finder")
 
;; nil

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil")
 
;; t
(require 's)  ;; All we need is `s-matches-p'
(require 'rx)

;; Your example -----------------------------------------------------------

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil_finder")
;; t

(s-matches-p (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") "nil")
;; t

;; Fixed ------------------------------------------------------------------

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil_finder")
;; nil

(s-matches-p
 (concat
  (rx symbol-start)
  (regexp-opt '("nil" "t") t)
  (rx symbol-end))
 "nil")
;; t

;; Better way --------------------------------------------------------------

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil_finder")
;; n

(s-matches-p (rx symbol-start (or "nil" "t") symbol-end) "nil")
;; n
Source Link
serghei
  • 282
  • 4
  • 15
Loading