S
S
sedoyky4er2021-07-13 22:19:51
JavaScript
sedoyky4er, 2021-07-13 22:19:51

How to solve this regex?

Good afternoon, code mastodons.

I retired a long time ago, but now I'm faced with a problem that I want to solve as soon as possible and need your help.

There is a "site" on a tilde. The task is to create pages for a branch, but there are different addresses and information. To remove unnecessary blocks resorted to the code below. This code works, but if the link looks like this https://site.com/sestr

If the link looks like this https://site.com/aboutsestr then the code no longer works. How to improve it so that if in the address bar, not just the word sestr, but aboutsestr, teamsestr, and so on, the code continues to work?

$(document).ready(function(){
 var pathname = window.location.pathname;
 switch (true) {
             /* Сестр*/
          case /(\/sestr\/)|(\/sestr$)/.test(pathname): 
            $('#rec154962019').css('display', 'none').css('opacity', '0');  
            $('#rec154962021').css('display', 'none').css('opacity', '0'); 
            $('#rec154865635').css('display', 'none').css('opacity', '0'); 
            $('#rec154865637').css('display', 'none').css('opacity', '0'); 
           break;
 /* Питер */ 
  default:
    $('#rec335613532').css('display', 'none').css('opacity', '0'); 
    $('#rec335628777').css('display', 'none').css('opacity', '0'); 
    $('#rec330784087').css('display', 'none').css('opacity', '0'); 
    $('#rec330775250').css('display', 'none').css('opacity', '0'); 
   
 }
});

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2021-07-13
@sedoyky4er

/sestr(?:\/|$)/

A
Aetae, 2021-07-13
@Aetae

Something like this:/\/[^\/]*sestr(\/|$)/

A
Alexander, 2021-07-13
@Aleksandr-JS-Developer

If I understand you correctly:

$(document).ready(function(){
 var pathname = window.location.pathname;
 switch (true) {
             /* Сестр*/
          case /sestr/.test(pathname): 
            $('#rec154962019').css('display', 'none').css('opacity', '0');  
            $('#rec154962021').css('display', 'none').css('opacity', '0'); 
            $('#rec154865635').css('display', 'none').css('opacity', '0'); 
            $('#rec154865637').css('display', 'none').css('opacity', '0'); 
           break;
 /* Питер */ 
  default:
    $('#rec335613532').css('display', 'none').css('opacity', '0'); 
    $('#rec335628777').css('display', 'none').css('opacity', '0'); 
    $('#rec330784087').css('display', 'none').css('opacity', '0'); 
    $('#rec330775250').css('display', 'none').css('opacity', '0'); 
   
 }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question